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
ProtocolRequestWriter
beginRequest
in interface ProtocolRequestWriter
java.io.IOException
- on a failed IO operationpublic ProtocolRequestWriter writeMethodName(java.lang.String name) throws java.io.IOException
ProtocolRequestWriter
writeMethodName
in interface ProtocolRequestWriter
name
- a non-null stringjava.io.IOException
- on a failed IO operationpublic ProtocolRequestWriter endRequest() throws java.io.IOException
ProtocolRequestWriter
endRequest
in interface ProtocolRequestWriter
java.io.IOException
- on a failed IO operationpublic ProtocolRequestWriter writeData(DataSource source) throws java.io.IOException
ProtocolRequestWriter
writeData
in interface ProtocolRequestWriter
source
- 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 ProtocolRequestWriter
writeName
in interface ProtocolWriter
name
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- 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 ProtocolRequestWriter
writeValue
in interface ProtocolWriter
value
- a floatjava.io.IOException
- on a failed IO operationpublic void close()
close
in interface ProtocolWriter
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable