Java Code Examples for java.io.OutputStream#getClass()
The following examples show how to use
java.io.OutputStream#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IonWriterSystemBinary.java From ion-java with Apache License 2.0 | 6 votes |
/** * @param out OutputStream the users output byte stream, if specified * @param autoFlush when true the writer flushes to the output stream * between top level values * @param ensureInitialIvm when true, an initial IVM will be emitted even * when the user doesn't explicitly write one. When false, an initial IVM * won't be emitted unless the user does it. That can result in an invalid * Ion stream if not used carefully. * @throws NullPointerException if any parameter is null. */ IonWriterSystemBinary(SymbolTable defaultSystemSymtab, OutputStream out, boolean autoFlush, boolean ensureInitialIvm) { super(defaultSystemSymtab, (ensureInitialIvm ? InitialIvmHandling.ENSURE : null), IvmMinimizing.ADJACENT); out.getClass(); // Efficient null check _user_output_stream = out; // the buffer manager and writer // are used to hold the buffered // binary values pending flush(). _manager = new BufferManager(); _writer = _manager.openWriter(); _auto_flush = autoFlush; }
Example 2
Source File: Files.java From joyqueue with Apache License 2.0 | 5 votes |
/** * 流拷贝,并刷盘 * * @param is 输入 * @param os 输出 * @param start 源起始位置 * @param length 长度 * @throws IOException */ public static void copy(final InputStream is, final OutputStream os, final long start, final long length) throws IOException { if (is == null || os == null || length == 0) { return; } if (is.getClass() == FileInputStream.class && os.getClass() == FileOutputStream.class) { // 采用zeroCopy技术拷贝 copy((FileInputStream) is, (FileOutputStream) os, start, length); } else { long bytes = 0; if (start > 0) { bytes = is.skip(start); if (bytes < start) { return; } } byte buffer[] = new byte[1024 * 4]; int c = 0; bytes = 0; while (bytes < length && ((c = is.read(buffer, 0, (int) Math.min(buffer.length, length - bytes))) >= 0)) { os.write(buffer, 0, c); bytes += c; } } }
Example 3
Source File: OutputStreamFastAppendable.java From ion-java with Apache License 2.0 | 5 votes |
OutputStreamFastAppendable(OutputStream out) { out.getClass(); // Efficient null check _out = out; _pos = 0; _byteBuffer = new byte[MAX_BYTES_LEN]; }
Example 4
Source File: Channels.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Constructs a channel that writes bytes to the given stream. * * <p> The resulting channel will not be buffered; it will simply redirect * its I/O operations to the given stream. Closing the channel will in * turn cause the stream to be closed. </p> * * @param out * The stream to which bytes are to be written * * @return A new writable byte channel */ public static WritableByteChannel newChannel(OutputStream out) { Objects.requireNonNull(out, "out"); if (out.getClass() == FileOutputStream.class) { return ((FileOutputStream) out).getChannel(); } return new WritableByteChannelImpl(out); }
Example 5
Source File: Channels.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Constructs a channel that writes bytes to the given stream. * * <p> The resulting channel will not be buffered; it will simply redirect * its I/O operations to the given stream. Closing the channel will in * turn cause the stream to be closed. </p> * * @param out * The stream to which bytes are to be written * * @return A new writable byte channel */ public static WritableByteChannel newChannel(OutputStream out) { Objects.requireNonNull(out, "out"); if (out.getClass() == FileOutputStream.class) { return ((FileOutputStream) out).getChannel(); } return new WritableByteChannelImpl(out); }