Skip to content

Commit

Permalink
[MISC] packet sequence correction for LOAD DATA LOCAL INFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Sep 23, 2015
1 parent d5fbf83 commit b01686a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PacketOutputStream extends OutputStream {
private OutputStream outputStream;

int seqNo;
int lastSeq;
int maxAllowedPacket;
boolean checkPacketLength;
boolean useCompression;
Expand Down Expand Up @@ -78,14 +79,16 @@ public void writeEmptyPacket(int seqNo) throws IOException {

/* Used by LOAD DATA INFILE. End of data is indicated by packet of length 0. */
public void sendFile(InputStream is, int seq) throws IOException {
startPacket(seq++, false);
this.seqNo = seq;
buffer.clear();
this.checkPacketLength=false;
byte[] buffer = new byte[8192];
int len;
while ((len = is.read(buffer)) > 0) {
write(buffer, 0, len);
}
finishPacket();
writeEmptyPacket(seq);
writeEmptyPacket(lastSeq);
}

public void sendStream(InputStream is, MySQLCharset charset) throws IOException {
Expand Down Expand Up @@ -131,6 +134,7 @@ public void finishPacket() throws IOException {
}
internalFlush();
buffer = ByteBuffer.allocate(1024).order(ByteOrder.LITTLE_ENDIAN);
this.lastSeq = this.seqNo;
this.seqNo = -1;
}

Expand Down

0 comments on commit b01686a

Please sign in to comment.