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:org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator.java

private void toggleLogs(boolean targetState) {
    if (Context.getAdministrationService()
            .getGlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME).equals("true")) {
        if (targetState == RestConstants.SWAGGER_LOGS_OFF) {
            // turn off the log4j loggers
            List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
            loggers.add(LogManager.getRootLogger());
            for (Logger logger : loggers) {
                originalLevels.put(logger.hashCode(), logger.getLevel());
                logger.setLevel(Level.OFF);
            }/*ww w. java 2  s .  c  om*/

            // silence stderr and stdout
            originalErr = System.err;
            System.setErr(new PrintStream(new OutputStream() {

                public void write(int b) {
                    // noop
                }
            }));

            originalOut = System.out;
            System.setOut(new PrintStream(new OutputStream() {

                public void write(int b) {
                    // noop
                }
            }));
        } else if (targetState == RestConstants.SWAGGER_LOGS_ON) {
            List<Logger> loggers = Collections.<Logger>list(LogManager.getCurrentLoggers());
            loggers.add(LogManager.getRootLogger());
            for (Logger logger : loggers) {
                logger.setLevel(originalLevels.get(logger.hashCode()));
            }

            System.setErr(originalErr);
            System.setOut(originalOut);
        }
    }
}

From source file:mitm.common.mail.MailUtils.java

/**
 * Checks whether the message can be converted to RFC2822 raw message source. Messages that
 * contain unsupported encoding types, corrupts content transfer encoding etc. will result
 * in a MessagingException or IOException.
 * @param message/*from   w ww.  ja  va  2s.  c om*/
 * @throws MessagingException
 * @throws IOException
 */
public static void validateMessage(MimeMessage message) throws MessagingException, IOException {
    OutputStream bitsink = new OutputStream() {
        @Override
        public void write(int ignore) {
        }
    };

    message.writeTo(bitsink);
}

From source file:com.github.jessemull.microflexdouble.math.AdditionTest.java

/**
 * Generates random objects and numbers for testing.
 *///from w  w w  .ja v  a2 s  .  c o  m
@BeforeClass
public static void setUp() {

    if (error) {

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

    }

    rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1);

    columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1);

    length = rows * columns / 5;

    for (int i = 0; i < stackNumber; i++) {

        plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

        Stack stack1 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate1-" + i,
                plateNumber);
        Stack stack2 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length, "Plate2-" + i,
                plateNumber);
        Stack stackUneven = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length + length / 2,
                "Plate2-" + i, plateNumber);

        stacks1.add(stack1);
        stacks2.add(stack2);
        stacksUneven.add(stackUneven);
    }

    for (int i = 0; i < arrayNumber; i++) {

        Plate[] array1 = new Plate[plateNumber];
        Plate[] array2 = new Plate[plateNumber];
        Plate[] unevenArray = new Plate[plateNumber];

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

            rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1);

            columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1);

            plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

            length = rows * columns / 5;

            Plate plate1 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length,
                    "Plate1-" + j);
            Plate plate2 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length,
                    "Plate2-" + j);
            Plate unevenPlate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue,
                    length + length / 2, "Plate2-" + j);

            array1[j] = plate1;
            array2[j] = plate2;
            unevenArray[j] = unevenPlate;
        }

        arrays1.add(array1);
        arrays2.add(array2);
        uneven.add(unevenArray);
    }

}

From source file:com.github.jessemull.microflexinteger.math.AdditionTest.java

/**
 * Generates random objects and numbers for testing.
 *//*from  ww  w .  j av  a  2  s .co  m*/
@BeforeClass
public static void setUp() {

    if (error) {

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

    }

    rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1);

    columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1);

    length = rows * columns / 5;

    for (int i = 0; i < stackNumber; i++) {

        plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

        Stack stack1 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate1-" + i,
                plateNumber);
        Stack stack2 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length, "Plate2-" + i,
                plateNumber);
        Stack stackUneven = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue,
                length + length / 2, "Plate2-" + i, plateNumber);

        stacks1.add(stack1);
        stacks2.add(stack2);
        stacksUneven.add(stackUneven);
    }

    for (int i = 0; i < arrayNumber; i++) {

        Plate[] array1 = new Plate[plateNumber];
        Plate[] array2 = new Plate[plateNumber];
        Plate[] unevenArray = new Plate[plateNumber];

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

            rows = Plate.ROWS_48WELL + random.nextInt(Plate.ROWS_1536WELL - Plate.ROWS_48WELL + 1);

            columns = Plate.COLUMNS_48WELL + random.nextInt(Plate.COLUMNS_1536WELL - Plate.COLUMNS_48WELL + 1);

            plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

            length = rows * columns / 5;

            Plate plate1 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length,
                    "Plate1-" + j);
            Plate plate2 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length,
                    "Plate2-" + j);
            Plate unevenPlate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue,
                    length + length / 2, "Plate2-" + j);

            array1[j] = plate1;
            array2[j] = plate2;
            unevenArray[j] = unevenPlate;
        }

        arrays1.add(array1);
        arrays2.add(array2);
        uneven.add(unevenArray);
    }

}

From source file:org.apache.brooklyn.entity.dns.geoscaling.GeoscalingWebClient.java

public GeoscalingWebClient(HttpClient httpClient) {
    this.httpClient = httpClient;
    this.tidy = new Tidy();
    // Silently swallow all HTML errors/warnings.
    tidy.setErrout(new PrintWriter(new OutputStream() {
        @Override/*from w w w.  ja  v  a 2 s .  c  o  m*/
        public void write(int b) throws IOException {
        }
    }));
}

From source file:com.github.vatbub.tictactoe.view.AnimationThreadPoolExecutor.java

@SuppressWarnings("unused")
public <T> Future<T> submitWaitForUnlock(Callable<T> task) {
    Callable<T> effectiveTask = () -> {
        // PrintStreams magically don't make the wait loop hang
        PrintStream nullStream = new PrintStream(new OutputStream() {
            public void write(int b) {
                //DO NOTHING
            }//w w  w. java 2 s . c  o m
        });
        while (isBlocked()) {
            nullStream.println("Waiting...");
        }
        // run
        FutureTask<T> effectiveCall = new FutureTask<>(task);
        Platform.runLater(effectiveCall);
        return effectiveCall.get();
    };
    return super.schedule(effectiveTask, 0, NANOSECONDS);
}

From source file:com.github.jessemull.microflex.math.mathdouble.AdditionDoubleTest.java

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

    if (error) {

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

    }

    rows = PlateDouble.ROWS_48WELL + random.nextInt(PlateDouble.ROWS_1536WELL - PlateDouble.ROWS_48WELL + 1);

    columns = PlateDouble.COLUMNS_48WELL
            + random.nextInt(PlateDouble.COLUMNS_1536WELL - PlateDouble.COLUMNS_48WELL + 1);

    length = rows * columns / 5;

    for (int i = 0; i < stackNumber; i++) {

        plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

        StackDouble stack1 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length,
                "Plate1-" + i, plateNumber);
        StackDouble stack2 = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue, length,
                "Plate2-" + i, plateNumber);
        StackDouble stackUneven = RandomUtil.randomStackDouble(rows, columns, minValue, maxValue,
                length + length / 2, "Plate2-" + i, plateNumber);

        stacks1.add(stack1);
        stacks2.add(stack2);
        stacksUneven.add(stackUneven);
    }

    for (int i = 0; i < arrayNumber; i++) {

        PlateDouble[] array1 = new PlateDouble[plateNumber];
        PlateDouble[] array2 = new PlateDouble[plateNumber];
        PlateDouble[] unevenArray = new PlateDouble[plateNumber];

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

            rows = PlateDouble.ROWS_48WELL
                    + random.nextInt(PlateDouble.ROWS_1536WELL - PlateDouble.ROWS_48WELL + 1);

            columns = PlateDouble.COLUMNS_48WELL
                    + random.nextInt(PlateDouble.COLUMNS_1536WELL - PlateDouble.COLUMNS_48WELL + 1);

            plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

            length = rows * columns / 5;

            PlateDouble plate1 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length,
                    "Plate1-" + j);
            PlateDouble plate2 = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length,
                    "Plate2-" + j);
            PlateDouble unevenPlate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue,
                    length + length / 2, "Plate2-" + j);

            array1[j] = plate1;
            array2[j] = plate2;
            unevenArray[j] = unevenPlate;
        }

        arrays1.add(array1);
        arrays2.add(array2);
        uneven.add(unevenArray);
    }

}

From source file:com.github.jessemull.microflex.math.mathinteger.AdditionIntegerTest.java

/**
 * Generates random objects and numbers for testing.
 *///from ww w  . ja  v a2 s .c o  m
@BeforeClass
public static void setUp() {

    if (error) {

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

    }

    rows = PlateInteger.ROWS_48WELL + random.nextInt(PlateInteger.ROWS_1536WELL - PlateInteger.ROWS_48WELL + 1);

    columns = PlateInteger.COLUMNS_48WELL
            + random.nextInt(PlateInteger.COLUMNS_1536WELL - PlateInteger.COLUMNS_48WELL + 1);

    length = rows * columns / 5;

    for (int i = 0; i < stackNumber; i++) {

        plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

        StackInteger stack1 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length,
                "Plate1-" + i, plateNumber);
        StackInteger stack2 = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue, length,
                "Plate2-" + i, plateNumber);
        StackInteger stackUneven = RandomUtil.randomStackInteger(rows, columns, minValue, maxValue,
                length + length / 2, "Plate2-" + i, plateNumber);

        stacks1.add(stack1);
        stacks2.add(stack2);
        stacksUneven.add(stackUneven);
    }

    for (int i = 0; i < arrayNumber; i++) {

        PlateInteger[] array1 = new PlateInteger[plateNumber];
        PlateInteger[] array2 = new PlateInteger[plateNumber];
        PlateInteger[] unevenArray = new PlateInteger[plateNumber];

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

            rows = PlateInteger.ROWS_48WELL
                    + random.nextInt(PlateInteger.ROWS_1536WELL - PlateInteger.ROWS_48WELL + 1);

            columns = PlateInteger.COLUMNS_48WELL
                    + random.nextInt(PlateInteger.COLUMNS_1536WELL - PlateInteger.COLUMNS_48WELL + 1);

            plateNumber = minPlate + random.nextInt(maxPlate - minPlate + 1);

            length = rows * columns / 5;

            PlateInteger plate1 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length,
                    "Plate1-" + j);
            PlateInteger plate2 = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length,
                    "Plate2-" + j);
            PlateInteger unevenPlate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue,
                    length + length / 2, "Plate2-" + j);

            array1[j] = plate1;
            array2[j] = plate2;
            unevenArray[j] = unevenPlate;
        }

        arrays1.add(array1);
        arrays2.add(array2);
        uneven.add(unevenArray);
    }

}

From source file:mitm.common.mail.MailUtils.java

/**
 * Checks whether the message can be converted to RFC2822 raw message source. Messages that
 * contain unsupported encoding types, corrupts content transfer encoding etc. will result
 * in a MessagingException or IOException.
 * @param message//  ww w.  j  a va  2s .  c om
 * @throws MessagingException
 * @throws IOException
 */
public static void validateMessage(Part part) throws MessagingException, IOException {
    OutputStream bitsink = new OutputStream() {
        @Override
        public void write(int ignore) {
        }
    };

    part.writeTo(bitsink);
}

From source file:com.cloudbees.hudson.plugins.folder.computed.EventOutputStreams.java

/**
 * Gets a new {@link OutputStream}, the caller must close the stream in order to ensure all its output gets written.
 *
 * @return a new {@link OutputStream}./*from w ww  . j a v  a2  s .  c o m*/
 */
public OutputStream get() {
    return new OutputStream() {
        private final byte[] buf = new byte[1024];
        private int index = 0;
        private long start = System.nanoTime();

        @Override
        public void write(int b) throws IOException {
            buf[index] = (byte) b;
            index++;
            lazyFlush();
        }

        private void lazyFlush() throws IOException {
            long end = System.nanoTime();
            if (index >= buf.length || end - start > flushIntervalNanos) {
                start = end;
                if (index == 0) {
                    return;
                }
                int count = index;
                for (int i = index - 1; i >= 0; i--) {
                    if (buf[i] == '\n') {
                        count = i + 1;
                        break;
                    }
                }
                if (index == count) { // send the whole buffer
                    offer(Arrays.copyOf(buf, count));
                    index = 0;
                } else { // send a partial buffer up to the last newline
                    offer(Arrays.copyOf(buf, count));
                    System.arraycopy(buf, count, buf, 0, index - count);
                    index -= count;
                }
            }
        }

        @Override
        public void write(byte[] data, int off, int len) throws IOException {
            if (data == null) {
                throw new NullPointerException();
            }
            if (index + len <= buf.length) {
                System.arraycopy(data, off, buf, index, len);
                index += len;
                lazyFlush();
            } else {
                while (len > 0) {
                    int l = Math.min(len, buf.length - index);
                    if (l > 0) {
                        System.arraycopy(data, off, buf, index, l);
                        index += l;
                        off += l;
                        len -= l;
                    }
                    lazyFlush();
                }
            }
        }

        @Override
        public void flush() throws IOException {
            start = System.nanoTime();
            if (index > 0) {
                offer(Arrays.copyOf(buf, index));
                index = 0;
            }
        }

        @Override
        public void close() throws IOException {
            flush();
            offer(null); // force a flush to disk
        }
    };
}