@Test(expected = IllegalArgumentException.class) public void readStringUTF8ThrowsIfTryingToReadNegativeAmountOfCharacters() { reader.readStringUTF8(process, 0, -1512); }
@Override public String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } byte[] buffer = new byte[maxCodeUnitsToRead]; int bytesRead = 0; for (int i = 0; i < maxCodeUnitsToRead; i++) { byte readByte = readByte(process, offset + i); if (readByte == 0) { break; } buffer[i] = readByte; bytesRead++; } return new String(buffer, 0, bytesRead, StandardCharsets.UTF_8); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } byte[] buffer = new byte[maxCodeUnitsToRead]; int bytesRead = 0; for (int i = 0; i < maxCodeUnitsToRead; i++) { byte readByte = readByte(process, offset + i); if (readByte == 0) { break; } buffer[i] = readByte; bytesRead++; } return new String(buffer, 0, bytesRead, StandardCharsets.UTF_8); } }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } byte[] buffer = new byte[maxCodeUnitsToRead]; int bytesRead = 0; for (int i = 0; i < maxCodeUnitsToRead; i++) { byte readByte = readByte(process, offset + i); if (readByte == 0) { break; } buffer[i] = readByte; bytesRead++; } return new String(buffer, 0, bytesRead, StandardCharsets.UTF_8); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } byte[] buffer = new byte[maxCodeUnitsToRead]; int bytesRead = 0; for (int i = 0; i < maxCodeUnitsToRead; i++) { byte readByte = readByte(process, offset + i); if (readByte == 0) { break; } buffer[i] = readByte; bytesRead++; } return new String(buffer, 0, bytesRead, StandardCharsets.UTF_8); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); @Override boolean readBoolean(NativeProcess process, int offset); @Override byte readByte(NativeProcess process, int offset); @Override char readCharUTF8(NativeProcess process, int offset); @Override char readCharUTF16LE(NativeProcess process, int offset); @Override short readShort(NativeProcess process, int offset); @Override int readInt(NativeProcess process, int offset); @Override float readFloat(NativeProcess process, int offset); @Override long readLong(NativeProcess process, int offset); @Override double readDouble(NativeProcess process, int offset); @Override String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override byte[] read(NativeProcess process, int offset, int bytesToRead); }
MemoryReaderImpl implements MemoryReader { @Override public String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead) { if (maxCodeUnitsToRead < 1) { throw new IllegalArgumentException("Cannot read strings shorter than 1 character!"); } byte[] buffer = new byte[maxCodeUnitsToRead]; int bytesRead = 0; for (int i = 0; i < maxCodeUnitsToRead; i++) { byte readByte = readByte(process, offset + i); if (readByte == 0) { break; } buffer[i] = readByte; bytesRead++; } return new String(buffer, 0, bytesRead, StandardCharsets.UTF_8); } MemoryReaderImpl(RawMemoryReader rawMemoryReader); @Override boolean readBoolean(NativeProcess process, int offset); @Override byte readByte(NativeProcess process, int offset); @Override char readCharUTF8(NativeProcess process, int offset); @Override char readCharUTF16LE(NativeProcess process, int offset); @Override short readShort(NativeProcess process, int offset); @Override int readInt(NativeProcess process, int offset); @Override float readFloat(NativeProcess process, int offset); @Override long readLong(NativeProcess process, int offset); @Override double readDouble(NativeProcess process, int offset); @Override String readStringUTF8(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override String readStringUTF16LE(NativeProcess process, int offset, int maxCodeUnitsToRead); @Override byte[] read(NativeProcess process, int offset, int bytesToRead);  }