public class PacketOutputStream extends OutputStream
Modifier and Type | Field and Description |
---|---|
ByteBuffer |
buffer |
ByteBuffer |
firstBuffer |
OutputStream |
outputStream |
Constructor and Description |
---|
PacketOutputStream(OutputStream outputStream)
Initialization with server outputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
assureBufferCapacity(int len)
Ensure that the buffer remaining size permit to write a data with a size len.
|
boolean |
checkRewritableLength(int length)
Check that current buffer + length will not be superior to max_allowed_packet + header size.
|
void |
close() |
void |
finishPacket()
Ending command that tell to send buffer to server.
|
void |
flush() |
protected void |
increase(int newCapacity) |
void |
sendFile(InputStream is,
int seq)
Used to send LOAD DATA INFILE.
|
void |
sendPreparePacket(String sql)
Send directly to socket the sql data.
|
void |
sendStream(InputStream is)
Send stream to server.
|
void |
sendStream(InputStream is,
long readLength)
Send stream to server.
|
void |
sendStream(Reader reader)
Send reader stream to server.
|
void |
sendStream(Reader reader,
long readLength)
Send reader stream to server.
|
void |
sendTextPacket(String sql)
Send directly to socket the sql data.
|
void |
setMaxAllowedPacket(int maxAllowedPacket)
Initialize maximal send size (can be send in multiple stream).
|
void |
setUseCompression(boolean useCompression) |
void |
startPacket(int seqNo)
Initialize stream sequence.
|
void |
startPacket(int seqNo,
boolean checkPacketLength)
Initialize stream sequence.
|
void |
write(byte[] bytes) |
void |
write(byte[] bytes,
int off,
int len) |
void |
write(int byteInt) |
PacketOutputStream |
writeByte(byte theByte)
Write a byte data to buffer.
|
PacketOutputStream |
writeByteArray(byte[] bytes)
Write byte array to buffer.
|
PacketOutputStream |
writeByteArrayLength(byte[] bytes)
Write byte array data to binary data.
|
PacketOutputStream |
writeBytes(byte theByte,
int count)
Write count time the byte value.
|
PacketOutputStream |
writeDateLength(Calendar calendar)
Write date in binary format.
|
void |
writeEmptyPacket(int seqNo)
Send an empty stream to server.
|
PacketOutputStream |
writeFieldLength(long length)
Write field length to encode in binary format.
|
PacketOutputStream |
writeInt(int theInt)
Write int data in binary format.
|
PacketOutputStream |
writeLong(long theLong)
Write long data in binary format.
|
PacketOutputStream |
writeShort(short theShort)
Write short data in binary format.
|
PacketOutputStream |
writeString(String str)
Write string data in binary format.
|
PacketOutputStream |
writeStringLength(String str)
Write string in binary format.
|
PacketOutputStream |
writeTimeLength(Calendar calendar,
boolean fractionalSeconds)
Write time in binary format.
|
PacketOutputStream |
writeTimestampLength(Calendar calendar,
Timestamp ts,
boolean fractionalSeconds)
Write timestamp in binary format.
|
public ByteBuffer buffer
public ByteBuffer firstBuffer
public OutputStream outputStream
public PacketOutputStream(OutputStream outputStream)
outputStream
- server outPutStreamprotected void increase(int newCapacity)
public void setUseCompression(boolean useCompression)
public void startPacket(int seqNo, boolean checkPacketLength) throws IOException
seqNo
- stream sequence numbercheckPacketLength
- indication that max stream allowed size will be checked.IOException
- if any error occur during data send to serverpublic void startPacket(int seqNo) throws IOException
seqNo
- stream sequence numberIOException
- if any error occur during data send to serverpublic void writeEmptyPacket(int seqNo) throws IOException
seqNo
- stream sequence numberIOException
- if any error occur during data send to serverpublic void sendFile(InputStream is, int seq) throws IOException
is
- inputStream to sendseq
- stream sequence numberIOException
- if any error occur during data send to serverpublic void sendStream(InputStream is) throws IOException
is
- inputStream to sendIOException
- if any error occur during data send to serverpublic void sendStream(InputStream is, long readLength) throws IOException
is
- inputStream to sendreadLength
- max size to sendIOException
- if any error occur during data send to serverpublic void sendStream(Reader reader) throws IOException
reader
- reader to sendIOException
- if any error occur during data send to serverpublic void sendStream(Reader reader, long readLength) throws IOException
reader
- reader to sendreadLength
- max size to sendIOException
- if any error occur during data send to serverpublic void finishPacket() throws IOException
IOException
- if any connection error occurpublic void write(byte[] bytes) throws IOException
write
in class OutputStream
IOException
public void write(int byteInt) throws IOException
write
in class OutputStream
IOException
public void write(byte[] bytes, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public boolean checkRewritableLength(int length)
length
- additionnal lengthpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void setMaxAllowedPacket(int maxAllowedPacket)
maxAllowedPacket
- value of server maxAllowedPacketpublic void assureBufferCapacity(int len)
len
- size of the datapublic PacketOutputStream writeByte(byte theByte)
theByte
- byte to writepublic PacketOutputStream writeBytes(byte theByte, int count)
theByte
- byte to write to buffercount
- number of time the value will be put to bufferpublic PacketOutputStream writeByteArray(byte[] bytes)
bytes
- byte arraypublic PacketOutputStream writeByteArrayLength(byte[] bytes)
bytes
- byte array to encodepublic PacketOutputStream writeString(String str)
str
- string value to encodepublic PacketOutputStream writeShort(short theShort)
theShort
- short data to encodepublic PacketOutputStream writeInt(int theInt)
theInt
- int datapublic PacketOutputStream writeLong(long theLong)
theLong
- long datapublic PacketOutputStream writeFieldLength(long length)
length
- data length to encodepublic PacketOutputStream writeStringLength(String str)
str
- string to encodepublic PacketOutputStream writeTimestampLength(Calendar calendar, Timestamp ts, boolean fractionalSeconds)
calendar
- session calendarts
- timestamp to sendfractionalSeconds
- must fractionnal second be send to serverpublic PacketOutputStream writeDateLength(Calendar calendar)
calendar
- datepublic PacketOutputStream writeTimeLength(Calendar calendar, boolean fractionalSeconds)
calendar
- session calendar.fractionalSeconds
- fractional seconds must be sendpublic void sendPreparePacket(String sql) throws IOException, QueryException
sql
- the queryIOException
- if connection error occurQueryException
- if packet max size is to big.public void sendTextPacket(String sql) throws IOException, QueryException
sql
- the queryIOException
- if connection error occurQueryException
- if packet max size is to big.Copyright © 2016. All rights reserved.