Package org.elasticsearch.common.io
Class UTF8StreamWriter
java.lang.Object
java.io.Writer
org.elasticsearch.common.io.UTF8StreamWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoidclose()Closes andresetsthis writer for reuse.voidflush()Flushes the stream.voidreset()setOutput(OutputStream out)Sets the output stream to use for writing until this writer is closed.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(CharSequence csq)Writes the specified character sequence.voidWrites a portion of a string.
-
Constructor Details
-
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 Details
-
setOutput
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]- Parameters:
out- the output stream.- Returns:
- this UTF-8 writer.
- Throws:
IllegalStateException- if this writer is being reused and it has not beenclosedorreset.
-
write
Writes a single character. This method supports 16-bits character surrogates.- Parameters:
c-charthe character to be written (possibly a surrogate).- Throws:
IOException- if an I/O error occurs.
-
write
Writes a character given its 31-bits Unicode.- Overrides:
writein classWriter- Parameters:
code- the 31 bits Unicode of the character to be written.- Throws:
IOException- if an I/O error occurs.
-
write
Writes a portion of an array of characters.- Specified by:
writein classWriter- Parameters:
cbuf- the array of characters.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
IOException- if an I/O error occurs.
-
write
Writes a portion of a string.- Overrides:
writein classWriter- Parameters:
str- a String.off- the offset from which to start writing characters.len- the number of characters to write.- Throws:
IOException- if an I/O error occurs
-
write
Writes the specified character sequence.- Parameters:
csq- the character sequence.- Throws:
IOException- if an I/O error occurs
-
flush
Flushes 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 interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- if an I/O error occurs.
-
close
Closes andresetsthis writer for reuse.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- if an I/O error occurs
-
reset
public void reset()
-