@Test public void readsCorrectDataFromCorrectFile() throws IOException { Integer pid = 5567; Path memFile = procRoot.resolve(pid + "").resolve("mem"); byte[] inputData = TestUtils.generateRandomBytes(200); assertTrue(Files.notExists(memFile)); Files.createDirectories(memFile.getParent()); Files.write(memFile, inputData); SeekableByteChannel stream = provider.openRead(pid); ByteBuffer readBuffer = ByteBuffer.allocate(inputData.length); int bytesRead = stream.read(readBuffer); assertEquals(inputData.length, bytesRead); assertArrayEquals(inputData, readBuffer.array()); }
@Override public SeekableByteChannel openRead(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.READ); } catch (IOException ex) { String message = String.format( "Failed to open process %d for reading! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openRead(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.READ); } catch (IOException ex) { String message = String.format( "Failed to open process %d for reading! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openRead(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.READ); } catch (IOException ex) { String message = String.format( "Failed to open process %d for reading! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } FileMemoryProvider(Path procRoot); }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openRead(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.READ); } catch (IOException ex) { String message = String.format( "Failed to open process %d for reading! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } FileMemoryProvider(Path procRoot); @Override SeekableByteChannel openRead(int pid); @Override SeekableByteChannel openWrite(int pid); }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openRead(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.READ); } catch (IOException ex) { String message = String.format( "Failed to open process %d for reading! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } FileMemoryProvider(Path procRoot); @Override SeekableByteChannel openRead(int pid); @Override SeekableByteChannel openWrite(int pid);  }