Package com.yahoo.io
Class AbstractByteWriter
- java.lang.Object
-
- java.io.Writer
-
- com.yahoo.text.GenericWriter
-
- com.yahoo.io.AbstractByteWriter
-
- All Implemented Interfaces:
WritableByteTransmitter
,Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
ByteWriter
,Utf8ByteWriter
public abstract class AbstractByteWriter extends GenericWriter implements WritableByteTransmitter
Base class for writers needing to accept binary data.- Author:
- Steinar Knutsen, baldersheim
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferChain
buffer
protected CharBuffer
charBuffer
protected CharsetEncoder
encoder
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractByteWriter(CharsetEncoder encoder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(byte alreadyEncoded)
void
append(byte[] alreadyEncoded)
void
append(byte[] alreadyEncoded, int offset, int length)
void
append(ByteBuffer alreadyEncoded)
long
appended()
Return the number of bytes this writer will produce for the underlying layer.Charset
getEncoding()
Returns the charset this encodes its output inGenericWriter
write(boolean v)
void
write(char[] cbuf, int offset, int len)
GenericWriter
write(double v)
GenericWriter
write(float v)
void
write(int v)
Do note, if writing the first character of a surrogate pair, the next character written must be the second part of the pair.GenericWriter
write(long v)
GenericWriter
write(short v)
GenericWriter
write(AbstractUtf8Array v)
-
Methods inherited from class com.yahoo.text.GenericWriter
write, write, write
-
Methods inherited from class java.io.Writer
append, append, append, close, flush, nullWriter, write, write, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.yahoo.io.WritableByteTransmitter
send
-
-
-
-
Field Detail
-
encoder
protected final CharsetEncoder encoder
-
buffer
protected final BufferChain buffer
-
charBuffer
protected final CharBuffer charBuffer
-
-
Constructor Detail
-
AbstractByteWriter
protected AbstractByteWriter(CharsetEncoder encoder)
-
-
Method Detail
-
getEncoding
public Charset getEncoding()
Returns the charset this encodes its output in
-
write
public GenericWriter write(AbstractUtf8Array v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public GenericWriter write(long v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public void write(int v) throws IOException
Do note, if writing the first character of a surrogate pair, the next character written must be the second part of the pair. If this is not the case, the surrogate will be omitted from output.- Overrides:
write
in classWriter
- Throws:
IOException
-
write
public GenericWriter write(double v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public GenericWriter write(float v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public GenericWriter write(short v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public GenericWriter write(boolean v) throws IOException
- Overrides:
write
in classGenericWriter
- Throws:
IOException
-
write
public void write(char[] cbuf, int offset, int len) throws IOException
- Specified by:
write
in classWriter
- Throws:
IOException
-
append
public void append(ByteBuffer alreadyEncoded) throws IOException
- Throws:
IOException
-
append
public void append(byte alreadyEncoded) throws IOException
- Throws:
IOException
-
append
public void append(byte[] alreadyEncoded) throws IOException
- Throws:
IOException
-
append
public void append(byte[] alreadyEncoded, int offset, int length) throws IOException
- Throws:
IOException
-
appended
public long appended()
Return the number of bytes this writer will produce for the underlying layer. That is, it sums the length of the raw bytes received and the number of bytes in the written strings after encoding.- Returns:
- the number of bytes appended to this writer
-
-