Package org.elasticsearch.common.io
Class UTF8StreamWriter
- java.lang.Object
-
- java.io.Writer
-
- org.elasticsearch.common.io.UTF8StreamWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public final class UTF8StreamWriter extends java.io.Writer
-
-
Constructor Summary
Constructors Constructor Description UTF8StreamWriter()Creates a UTF-8 writer having a byte buffer of moderate capacity (2048).UTF8StreamWriter(int capacity)Creates a UTF-8 writer having a byte buffer of specified capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Closes andresetsthis writer for reuse.voidflush()Flushes the stream.voidreset()UTF8StreamWritersetOutput(java.io.OutputStream out)Sets the output stream to use for writing until this writer is closed.UTF8StreamWritersetOutputStream(java.io.OutputStream out)Deprecated.Replaced bysetOutput(OutputStream)voidwrite(char c)Writes a single character.voidwrite(char[] cbuf, int off, int len)Writes a portion of an array of characters.voidwrite(int code)Writes a character given its 31-bits Unicode.voidwrite(java.lang.CharSequence csq)Writes the specified character sequence.voidwrite(java.lang.String str, int off, int len)Writes a portion of a string.
-
-
-
Constructor Detail
-
UTF8StreamWriter
public UTF8StreamWriter()
Creates a UTF-8 writer having a byte buffer of moderate capacity (2048).
-
UTF8StreamWriter
public UTF8StreamWriter(int capacity)
Creates a UTF-8 writer having a byte buffer of specified capacity.- Parameters:
capacity- the capacity of the byte buffer.
-
-
Method Detail
-
setOutput
public UTF8StreamWriter setOutput(java.io.OutputStream out)
Sets the output stream to use for writing until this writer is closed. For example:[code] Writer writer = new UTF8StreamWriter().setOutputStream(out); [/code] is equivalent but writes faster than [code] Writer writer = new java.io.OutputStreamWriter(out, "UTF-8"); [/code]
-
write
public void write(char c) throws java.io.IOExceptionWrites a single character. This method supports 16-bits character surrogates.- Parameters:
c-charthe character to be written (possibly a surrogate).- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(int code) throws java.io.IOExceptionWrites a character given its 31-bits Unicode.- Overrides:
writein classjava.io.Writer- Parameters:
code- the 31 bits Unicode of the character to be written.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrites a portion of an array of characters.- Specified by:
writein classjava.io.Writer- Parameters:
cbuf- the array of characters.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOExceptionWrites a portion of a string.- Overrides:
writein classjava.io.Writer- Parameters:
str- a String.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
java.io.IOException- if an I/O error occurs
-
write
public void write(java.lang.CharSequence csq) throws java.io.IOExceptionWrites the specified character sequence.- Parameters:
csq- the character sequence.- Throws:
java.io.IOException- if an I/O error occurs
-
flush
public void flush() throws java.io.IOExceptionFlushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionCloses andresetsthis writer for reuse.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException- if an I/O error occurs
-
reset
public void reset()
-
setOutputStream
@Deprecated public UTF8StreamWriter setOutputStream(java.io.OutputStream out)
Deprecated.Replaced bysetOutput(OutputStream)
-
-