@Test public void verifyScannerHandlesNegativeOneByteDelimiter() throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(new byte[] { 0, 0, 0, 0, -1, 0, 0, 0 }); StreamDemarcator scanner = new StreamDemarcator(is, new byte[] { -1 }, 20, 1024); assertArrayEquals(scanner.nextToken(), new byte[] { 0, 0, 0, 0 }); assertArrayEquals(scanner.nextToken(), new byte[] { 0, 0, 0 }); }
public byte[] nextToken() throws IOException { byte[] token = null; int j = 0; nextTokenLoop: while (token == null && this.availableBytesLength != -1) { if (this.index >= this.availableBytesLength) { this.fill(); } if (this.availableBytesLength != -1) { byte byteVal; int i; for (i = this.index; i < this.availableBytesLength; i++) { byteVal = this.buffer[i]; boolean delimiterFound = false; if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) { if (++j == this.delimiterBytes.length) { delimiterFound = true; } } else { j = 0; } if (delimiterFound) { this.index = i + 1; int size = this.index - this.mark - this.delimiterBytes.length; token = this.extractDataToken(size); this.mark = this.index; j = 0; if (token != null) { break nextTokenLoop; } } } this.index = i; } else { token = this.extractDataToken(this.index - this.mark); } } return token; }
StreamDemarcator extends AbstractDemarcator { public byte[] nextToken() throws IOException { byte[] token = null; int j = 0; nextTokenLoop: while (token == null && this.availableBytesLength != -1) { if (this.index >= this.availableBytesLength) { this.fill(); } if (this.availableBytesLength != -1) { byte byteVal; int i; for (i = this.index; i < this.availableBytesLength; i++) { byteVal = this.buffer[i]; boolean delimiterFound = false; if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) { if (++j == this.delimiterBytes.length) { delimiterFound = true; } } else { j = 0; } if (delimiterFound) { this.index = i + 1; int size = this.index - this.mark - this.delimiterBytes.length; token = this.extractDataToken(size); this.mark = this.index; j = 0; if (token != null) { break nextTokenLoop; } } } this.index = i; } else { token = this.extractDataToken(this.index - this.mark); } } return token; } }
StreamDemarcator extends AbstractDemarcator { public byte[] nextToken() throws IOException { byte[] token = null; int j = 0; nextTokenLoop: while (token == null && this.availableBytesLength != -1) { if (this.index >= this.availableBytesLength) { this.fill(); } if (this.availableBytesLength != -1) { byte byteVal; int i; for (i = this.index; i < this.availableBytesLength; i++) { byteVal = this.buffer[i]; boolean delimiterFound = false; if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) { if (++j == this.delimiterBytes.length) { delimiterFound = true; } } else { j = 0; } if (delimiterFound) { this.index = i + 1; int size = this.index - this.mark - this.delimiterBytes.length; token = this.extractDataToken(size); this.mark = this.index; j = 0; if (token != null) { break nextTokenLoop; } } } this.index = i; } else { token = this.extractDataToken(this.index - this.mark); } } return token; } StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize);  StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize, int initialBufferSize); }
StreamDemarcator extends AbstractDemarcator { public byte[] nextToken() throws IOException { byte[] token = null; int j = 0; nextTokenLoop: while (token == null && this.availableBytesLength != -1) { if (this.index >= this.availableBytesLength) { this.fill(); } if (this.availableBytesLength != -1) { byte byteVal; int i; for (i = this.index; i < this.availableBytesLength; i++) { byteVal = this.buffer[i]; boolean delimiterFound = false; if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) { if (++j == this.delimiterBytes.length) { delimiterFound = true; } } else { j = 0; } if (delimiterFound) { this.index = i + 1; int size = this.index - this.mark - this.delimiterBytes.length; token = this.extractDataToken(size); this.mark = this.index; j = 0; if (token != null) { break nextTokenLoop; } } } this.index = i; } else { token = this.extractDataToken(this.index - this.mark); } } return token; } StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize);  StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize, int initialBufferSize); byte[] nextToken(); }
StreamDemarcator extends AbstractDemarcator { public byte[] nextToken() throws IOException { byte[] token = null; int j = 0; nextTokenLoop: while (token == null && this.availableBytesLength != -1) { if (this.index >= this.availableBytesLength) { this.fill(); } if (this.availableBytesLength != -1) { byte byteVal; int i; for (i = this.index; i < this.availableBytesLength; i++) { byteVal = this.buffer[i]; boolean delimiterFound = false; if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) { if (++j == this.delimiterBytes.length) { delimiterFound = true; } } else { j = 0; } if (delimiterFound) { this.index = i + 1; int size = this.index - this.mark - this.delimiterBytes.length; token = this.extractDataToken(size); this.mark = this.index; j = 0; if (token != null) { break nextTokenLoop; } } } this.index = i; } else { token = this.extractDataToken(this.index - this.mark); } } return token; } StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize);  StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize, int initialBufferSize); byte[] nextToken();  }