package org.apache.jackrabbit.performance;

import java.io.InputStream;
import java.util.Random;

/**
 * An input stream that returns a given number of dummy data. The returned
 * data is designed to be non-compressible to prevent possible compression
 * mechanisms from affecting performance measurements.
 */
class TestInputStream extends InputStream {

    private final int n;

    private int i;

    /**
     * Source of the random stream of bytes. No fixed seed is used to
     * prevent a solution like the Jackrabbit data store from using just
     * a single storage location for multiple streams.
     */
    private final Random random = new Random();

    public TestInputStream(int length) {
        n = length;
        i = 0;
    }

    @Override
    public int read() {
        if (i < n) {
            i++;
            byte[] b = new byte[1];
            random.nextBytes(b);
            return b[0];
        } else {
            return -1;
        }
    }

    @Override
    public int read(byte[] b, int off, int len) {
        if (i < n) {
            byte[] data = new byte[Math.min(len, n - i)];
            random.nextBytes(data);
            System.arraycopy(data, 0, b, off, data.length);
            i += data.length;
            return data.length;
        } else {
            return -1;
        }
    }


}
@@ -1,8 +1,811 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

Merge jcr-benchmark into the performance test suite