@Test public void writesDataCorrectlyToCorrectFile() throws IOException { Integer pid = 10001; Path memFile = procRoot.resolve(pid + "").resolve("mem"); assertTrue(Files.notExists(memFile)); Files.createDirectories(memFile.getParent()); Files.createFile(memFile); byte[] bytesToWrite = TestUtils.generateRandomBytes(2048); SeekableByteChannel writeChannel = provider.openWrite(pid); writeChannel.write(ByteBuffer.wrap(bytesToWrite)); byte[] writtenBytes = Files.readAllBytes(memFile); assertArrayEquals(bytesToWrite, writtenBytes); }
@Override public SeekableByteChannel openWrite(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.WRITE); } catch (IOException ex) { String message = String.format( "Failed to open process %d for writing! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openWrite(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.WRITE); } catch (IOException ex) { String message = String.format( "Failed to open process %d for writing! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openWrite(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.WRITE); } catch (IOException ex) { String message = String.format( "Failed to open process %d for writing! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } FileMemoryProvider(Path procRoot); }
FileMemoryProvider implements ReadableMemoryProvider, WritableMemoryProvider { @Override public SeekableByteChannel openWrite(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.WRITE); } catch (IOException ex) { String message = String.format( "Failed to open process %d for writing! 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 openWrite(int pid) throws ProcessOpenException { Path memFile = createPathToProcessMemoryFile(pid); try { return Files.newByteChannel(memFile, StandardOpenOption.WRITE); } catch (IOException ex) { String message = String.format( "Failed to open process %d for writing! See getCause()!", pid ); throw new ProcessOpenException(message, ex); } } FileMemoryProvider(Path procRoot); @Override SeekableByteChannel openRead(int pid); @Override SeekableByteChannel openWrite(int pid);  }