Example usage for java.io OutputStream OutputStream

List of usage examples for java.io OutputStream OutputStream

Introduction

In this page you can find the example usage for java.io OutputStream OutputStream.

Prototype

OutputStream

Source Link

Usage

From source file:com.github.jessemull.microflexbiginteger.stat.MeanWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *///  ww  w .  j a va2  s. c o m
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        Plate plate = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        Plate plateIndices = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, lengthIndices,
                "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        weights[i] = random.nextDouble();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        weightsIndices[i] = random.nextDouble();
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MeanWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *//*w  ww .  j  a  v  a 2s.c  om*/
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        Plate plate = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        Plate plateIndices = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue, lengthIndices,
                "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        double randomDouble = random.nextDouble();
        weights[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        double randomDouble = random.nextDouble();
        weightsIndices[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }
}

From source file:nl.xs4all.home.freekdb.b52reader.general.Utilities.java

/**
 * Create an output stream that ignores everything that is written to it.
 *
 * @return an output stream that ignores everything.
 *///  w w  w  . ja v  a  2  s  . c  o  m
private static OutputStream getIgnorantStream() {
    return new OutputStream() {
        @Override
        public void write(final int b) throws IOException {
            // Ignore it.
        }
    };
}

From source file:org.apache.hadoop.http.HtmlQuoting.java

/**
 * Return an output stream that quotes all of the output.
 * @param out the stream to write the quoted output to
 * @return a new stream that the application show write to
 * @throws IOException if the underlying output fails
 *//*from   w  w w .  j ava  2s.c o  m*/
public static OutputStream quoteOutputStream(final OutputStream out) throws IOException {
    return new OutputStream() {
        private byte[] data = new byte[1];

        @Override
        public void write(byte[] data, int off, int len) throws IOException {
            quoteHtmlChars(out, data, off, len);
        }

        @Override
        public void write(int b) throws IOException {
            data[0] = (byte) b;
            quoteHtmlChars(out, data, 0, 1);
        }

        @Override
        public void flush() throws IOException {
            out.flush();
        }

        @Override
        public void close() throws IOException {
            out.close();
        }
    };
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.MeanBigIntegerWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *///from www .  java  2  s .  co  m
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        PlateBigInteger plate = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        PlateBigInteger plateIndices = RandomUtil.randomPlateBigInteger(rows, columns, minValue, maxValue,
                lengthIndices, "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        weights[i] = random.nextDouble();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        weightsIndices[i] = random.nextDouble();
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.MeanBigDecimalWeightsTest.java

/**
 * Generates random objects and numbers for testing.
 *///  w w  w  .  j  a v a 2  s .c  om
@BeforeClass
public static void setUp() {

    if (error) {

        System.setErr(new PrintStream(new OutputStream() {
            public void write(int x) {
            }
        }));

    }

    for (int j = 0; j < array.length; j++) {

        PlateBigDecimal plate = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue, length,
                "Plate1-" + j);

        array[j] = plate;
    }

    for (int j = 0; j < arrayIndices.length; j++) {

        PlateBigDecimal plateIndices = RandomUtil.randomPlateBigDecimal(rows, columns, minValue, maxValue,
                lengthIndices, "Plate1-" + j);

        arrayIndices[j] = plateIndices;
    }

    for (int i = 0; i < weights.length; i++) {
        double randomDouble = random.nextDouble();
        weights[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }

    for (int i = 0; i < weightsIndices.length; i++) {
        double randomDouble = random.nextDouble();
        weightsIndices[i] = new BigDecimal(randomDouble + "", contextWeights).doubleValue();
    }
}

From source file:com.mirth.connect.server.Mirth.java

public static OutputStream getNullOutputStream() {
    return new OutputStream() {
        public void write(int b) throws IOException {
            // ignore output
        }/*ww  w  .ja va  2s . c o  m*/
    };
}

From source file:ConsoleWindowTest.java

public static void init() {
    JFrame frame = new JFrame();
    frame.setTitle("ConsoleWindow");
    final JTextArea output = new JTextArea();
    output.setEditable(false);// w w  w  . j a  v  a  2 s .  c om
    frame.add(new JScrollPane(output));
    frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    frame.setLocation(DEFAULT_LEFT, DEFAULT_TOP);
    frame.setFocusableWindowState(false);
    frame.setVisible(true);

    // define a PrintStream that sends its bytes to the output text area
    PrintStream consoleStream = new PrintStream(new OutputStream() {
        public void write(int b) {
        } // never called

        public void write(byte[] b, int off, int len) {
            output.append(new String(b, off, len));
        }
    });

    // set both System.out and System.err to that stream
    System.setOut(consoleStream);
    System.setErr(consoleStream);
}

From source file:com.indeed.imhotep.iql.cache.HDFSQueryCache.java

@Override
public OutputStream getOutputStream(String cachedFileName) throws IOException {
    if (!enabled) {
        throw new IllegalStateException("Can't send data to HDFS cache as it is disabled");
    }//from w  ww.j  a va2s  .  c  om
    makeSurePathExists(cachePath);
    final Path filePath = new Path(cachePath, cachedFileName);
    final Path tempPath = new Path(filePath.toString() + "." + (System.currentTimeMillis() % 100000) + ".tmp");

    final FSDataOutputStream fileOut = hdfs.create(tempPath);
    // Wrap the returned OutputStream so that we can finish when it is closed
    return new OutputStream() {
        private boolean closed = false;

        @Override
        public void write(byte[] b) throws IOException {
            fileOut.write(b);
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            fileOut.write(b, off, len);
        }

        @Override
        public void flush() throws IOException {
            fileOut.flush();
        }

        @Override
        public void write(int b) throws IOException {
            fileOut.write(b);
        }

        @Override
        public void close() throws IOException {
            if (closed) {
                return;
            }
            closed = true;
            fileOut.close();

            // Move to the final file location
            hdfs.rename(tempPath, filePath);
        }
    };
}

From source file:com.indeed.imhotep.iql.cache.S3QueryCache.java

@Override
public OutputStream getOutputStream(final String cachedFileName) throws IOException {
    if (!enabled) {
        throw new IllegalStateException("Can't send data to S3 cache as it is disabled");
    }/*  w  w  w . j a v  a2 s .  co  m*/

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    // Wrap the returned OutputStream so that we can write to buffer and do actual write on close()
    return new OutputStream() {
        private boolean closed = false;

        @Override
        public void write(byte[] b) throws IOException {
            os.write(b);
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            os.write(b, off, len);
        }

        @Override
        public void flush() throws IOException {
            os.flush();
        }

        @Override
        public void write(int b) throws IOException {
            os.write(b);
        }

        @Override
        public void close() throws IOException {
            if (closed) {
                return;
            }
            closed = true;
            os.close();

            // do actual write
            byte[] csvData = os.toByteArray();
            ByteArrayInputStream is = new ByteArrayInputStream(csvData);
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(csvData.length);
            client.putObject(bucket, cachedFileName, is, metadata);
        }
    };
}