@Test public void testReadBlocksOfMemory() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}, 0, 0x10000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x10000); byte[] buffer = new byte[5]; assertEquals(5,sut.read(buffer)); assertEquals((byte)0xDE,buffer[0]); assertEquals((byte)0xAD,buffer[1]); assertEquals((byte)0xBE,buffer[2]); assertEquals((byte)0xEF,buffer[3]); assertEquals((byte)0xDE,buffer[4]); assertEquals(5,sut.read(buffer)); assertEquals((byte)0xAD,buffer[0]); assertEquals((byte)0xBE,buffer[1]); assertEquals((byte)0xEF,buffer[2]); assertEquals((byte)0xDE,buffer[3]); assertEquals((byte)0xAD,buffer[4]); }
@Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; }
IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } }
IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); }
IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); }
IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos);  }