public class BytesWriter extends java.lang.Object implements ProtocolRequestWriter
An implementation of a ProtocolRequestWriter which is able to write bytes into a BufferedSink
Generally used to write a network request
ProtocolWriter,
ProtocolRequestWriter,
BufferedSink| Constructor and Description |
|---|
BytesWriter(okio.BufferedSink sink)
Create a BytesReader instance
|
| Modifier and Type | Method and Description |
|---|---|
ProtocolRequestWriter |
beginRequest()
Start a request
|
void |
close()
Close the BufferedSink
|
ProtocolRequestWriter |
endRequest()
Finish a request
|
ProtocolRequestWriter |
writeData(DataSource source)
Set a DataSource as request data
|
ProtocolRequestWriter |
writeMethodName(java.lang.String name)
Write the method name of the request
|
ProtocolRequestWriter |
writeName(java.lang.String name)
Write the name of a parameter
|
ProtocolRequestWriter |
writeValue(boolean value)
Write the value of a parameter
|
ProtocolRequestWriter |
writeValue(double value)
Write the value of a parameter
|
ProtocolRequestWriter |
writeValue(float value)
Write the value of a parameter
|
ProtocolRequestWriter |
writeValue(long value)
Write the value of a parameter
|
ProtocolRequestWriter |
writeValue(java.lang.Object value)
Write the value of a parameter
|
ProtocolRequestWriter |
writeValue(java.lang.String value)
Write the value of a parameter
|
public BytesWriter(okio.BufferedSink sink)
sink - a BufferedSink to house the bytesjava.lang.IllegalArgumentException - on a null BufferedSink argumentpublic ProtocolRequestWriter beginRequest() throws java.io.IOException
ProtocolRequestWriterbeginRequest in interface ProtocolRequestWriterjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeMethodName(java.lang.String name) throws java.io.IOException
ProtocolRequestWriterwriteMethodName in interface ProtocolRequestWritername - a non-null stringjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter endRequest() throws java.io.IOException
ProtocolRequestWriterendRequest in interface ProtocolRequestWriterjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeData(DataSource source) throws java.io.IOException
ProtocolRequestWriterwriteData in interface ProtocolRequestWritersource - a non-null DataSource objectjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeName(java.lang.String name) throws java.io.IOException
ProtocolWriter
Every call of this method should be followed by a call to one the variants of writeValue()
writeName in interface ProtocolRequestWriterwriteName in interface ProtocolWritername - the non-null name of the parameterjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeValue(java.lang.Object value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
The provided argument must be a non-null object, of type String or any of the boxed variants of
primitive types. An object will be accepted if Class.isPrimitive() returns true for the object type.
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a non-null objectjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeValue(java.lang.String value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a non-null String objectjava.io.IOException - on failed IO operationspublic ProtocolRequestWriter writeValue(long value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a longjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeValue(boolean value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a booleanjava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeValue(double value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a doublejava.io.IOException - on a failed IO operationpublic ProtocolRequestWriter writeValue(float value) throws java.io.IOException
ProtocolWriter
Every call to this or the other variants of writeValue() should be preceded by a call to
ProtocolWriter.writeName(String).
writeValue in interface ProtocolRequestWriterwriteValue in interface ProtocolWritervalue - a floatjava.io.IOException - on a failed IO operationpublic void close()
close in interface ProtocolWriterclose in interface java.io.Closeableclose in interface java.lang.AutoCloseable