ByteArrayDataInput extends InputStream implements DataInput, VersionedDataStream { @Override public String readLine() { if (pos >= nBytes) { return null; } int startIdx = pos; int lastIdx = -1; while (lastIdx == -1) { int c = readByteAsInt(); switch (c) { case -1: lastIdx = pos; break; case '\n': lastIdx = pos - 1; break; case '\r': lastIdx = pos - 1; int c2 = readByteAsInt(); if (c2 != '\n' && c2 != -1) { pos--; } break; } } @SuppressWarnings("deprecation") final String string = new String(bytes, 0, startIdx, lastIdx - startIdx); return string; } ByteArrayDataInput();  ByteArrayDataInput(byte[] bytes);  ByteArrayDataInput(byte[] bytes, KnownVersion version); void initialize(byte[] bytes, KnownVersion version); @Override KnownVersion getVersion(); @Override int read(); @Override int read(byte[] b, int off, int len); @Override long skip(long n); @Override int available(); int position(); void setPosition(int pos); @Override void readFully(byte[] b); @Override void readFully(byte[] b, int off, int len); @Override int skipBytes(int n); @Override boolean readBoolean(); @Override byte readByte(); @Override int readUnsignedByte(); @Override short readShort(); @Override int readUnsignedShort(); @Override char readChar(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override String readUTF(); @Override String readLine(); @Override void close(); @Override String toString();  }
@Test public void readLineGivenEmptyLineTerminatedByLineFeedReturnsEmptyString() throws IOException { byte[] inputBytes = new byte[] {'\n'}; DataInput input = createDataInput(inputBytes); String result = input.readLine(); assertThat(result).isEmpty(); assertThat(dataRemaining(input)).isEqualTo(0); }
@Test public void readLineGivenEmptyLineTerminatedByCarriageReturnReturnsEmptyString() throws IOException { byte[] inputBytes = new byte[] {'\r'}; DataInput input = createDataInput(inputBytes); String result = input.readLine(); assertThat(result).isEmpty(); assertThat(dataRemaining(input)).isEqualTo(0); }
@Test public void readLineGivenEmptyLineTerminatedByCarriageReturnLineFeedReturnsEmptyString() throws IOException { byte[] inputBytes = new byte[] {'\r', '\n'}; DataInput input = createDataInput(inputBytes); String result = input.readLine(); assertThat(result).isEmpty(); assertThat(dataRemaining(input)).isEqualTo(0); }
@Test public void readLineGivenLineTerminatedByEOFReturnsCorrectLineData() throws IOException { byte[] inputBytes = new byte[] {'a', 'b', 'c'}; DataInput input = createDataInput(inputBytes); String result = input.readLine(); assertThat(result).isEqualTo("abc"); assertThat(dataRemaining(input)).isEqualTo(0); }