* @return A new reader */ public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) { checkNotNull(ch, "ch"); return StreamDecoder.forDecoder(ch, dec.reset(), minBufferCap); } /** * Constructs a reader that decodes bytes from the given channel according * to the named charset. * * <p> An invocation of this method of the form * * <blockquote><pre> * Channels.newReader(ch, csname)</pre></blockquote> * * behaves in exactly the same way as the expression * * <blockquote><pre> * Channels.newReader(ch, * Charset.forName(csName) * .newDecoder(), * -1);</pre></blockquote> * * @param ch * The channel from which bytes will be read * * @param csName * The name of the charset to be used * * @return A new reader * * @throws UnsupportedCharsetException * If no support for the named charset is available * in this instance of the Java virtual machine */ public static Reader newReader(ReadableByteChannel ch, String csName) { checkNotNull(csName, "csName"); return newReader(ch, Charset.forName(csName).newDecoder(), -1); } /** * Constructs a writer that encodes characters using the given encoder and * writes the resulting bytes to the given channel. * * <p> The resulting stream will contain an internal output buffer of at * least <tt>minBufferCap</tt> bytes. The stream's <tt>write</tt> methods * will, as needed, flush the buffer by writing bytes to the underlying * channel; if the channel is in non-blocking mode when bytes are to be * written then an {@link IllegalBlockingModeException} will be thrown. * The resulting stream will not otherwise be buffered. Closing the stream * will in turn cause the channel to be closed. </p> * * @param ch * The channel to which bytes will be written * * @param enc * The charset encoder to be used * * @param minBufferCap * The minimum capacity of the internal byte buffer, * or <tt>-1</tt> if an implementation-dependent * default capacity is to be used * * @return A new writer */ public static Writer newWriter(final WritableByteChannel ch, final CharsetEncoder enc, final int minBufferCap) { checkNotNull(ch, "ch"); return StreamEncoder.forEncoder(ch, enc.reset(), minBufferCap); } /** * Constructs a writer that encodes characters according to the named * charset and writes the resulting bytes to the given channel. * * <p> An invocation of this method of the form * * <blockquote><pre> * Channels.newWriter(ch, csname)</pre></blockquote> * * behaves in exactly the same way as the expression * * <blockquote><pre> * Channels.newWriter(ch, * Charset.forName(csName) * .newEncoder(), * -1);</pre></blockquote> * * @param ch * The channel to which bytes will be written * * @param csName * The name of the charset to be used * * @return A new writer * * @throws UnsupportedCharsetException * If no support for the named charset is available * in this instance of the Java virtual machine */ public static Writer newWriter(WritableByteChannel ch, String csName) { checkNotNull(csName, "csName"); return newWriter(ch, Charset.forName(csName).newEncoder(), -1); }}Lines 501–615 of 615. Previous lines
* @return A new reader */ public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) { checkNotNull(ch, "ch"); return StreamDecoder.forDecoder(ch, dec.reset(), minBufferCap); } /** * Constructs a reader that decodes bytes from the given channel according * to the named charset. * * <p> An invocation of this method of the form * * <blockquote><pre> * Channels.newReader(ch, csname)</pre></blockquote> * * behaves in exactly the same way as the expression * * <blockquote><pre> * Channels.newReader(ch, * Charset.forName(csName) * .newDecoder(), * -1);</pre></blockquote> * * @param ch * The channel from which bytes will be read * * @param csName * The name of the charset to be used * * @return A new reader * * @throws UnsupportedCharsetException * If no support for the named charset is available * in this instance of the Java virtual machine */ public static Reader newReader(ReadableByteChannel ch, String csName) { checkNotNull(csName, "csName"); return newReader(ch, Charset.forName(csName).newDecoder(), -1); } /** * Constructs a writer that encodes characters using the given encoder and * writes the resulting bytes to the given channel. * * <p> The resulting stream will contain an internal output buffer of at * least <tt>minBufferCap</tt> bytes. The stream's <tt>write</tt> methods * will, as needed, flush the buffer by writing bytes to the underlying * channel; if the channel is in non-blocking mode when bytes are to be * written then an {@link IllegalBlockingModeException} will be thrown. * The resulting stream will not otherwise be buffered. Closing the stream * will in turn cause the channel to be closed. </p> * * @param ch * The channel to which bytes will be written * * @param enc * The charset encoder to be used * * @param minBufferCap * The minimum capacity of the internal byte buffer, * or <tt>-1</tt> if an implementation-dependent * default capacity is to be used * * @return A new writer */ public static Writer newWriter(final WritableByteChannel ch, final CharsetEncoder enc, final int minBufferCap) { checkNotNull(ch, "ch"); return StreamEncoder.forEncoder(ch, enc.reset(), minBufferCap); } /** * Constructs a writer that encodes characters according to the named * charset and writes the resulting bytes to the given channel. * * <p> An invocation of this method of the form * * <blockquote><pre> * Channels.newWriter(ch, csname)</pre></blockquote> * * behaves in exactly the same way as the expression * * <blockquote><pre> * Channels.newWriter(ch, * Charset.forName(csName) * .newEncoder(), * -1);</pre></blockquote> * * @param ch * The channel to which bytes will be written * * @param csName * The name of the charset to be used * * @return A new writer * * @throws UnsupportedCharsetException * If no support for the named charset is available * in this instance of the Java virtual machine */ public static Writer newWriter(WritableByteChannel ch, String csName) { checkNotNull(csName, "csName"); return newWriter(ch, Charset.forName(csName).newEncoder(), -1); } }