gnodet commented on PR #1281: URL: https://github.com/apache/maven-mvnd/pull/1281#issuecomment-2705728187
I'm not completely at ease with dropping the shared memory mapped file which afaik, will result in a performance loss. The use of this memory mapped file seems really a good use case, as one daemon will write and others will be automatically updated without having to re-read the files (or that's the theory at least). If we want to simplify things and use a DataInputStream / DataOutputStream (which I agree would be nicer), we can wrap the buffer in streams: ``` class MappedByteBufferInputStream extends InputStream { private final MappedByteBuffer buffer; public MappedByteBufferInputStream(MappedByteBuffer buffer) { this.buffer = buffer; } @Override public int read() throws IOException { if (!buffer.hasRemaining()) { return -1; } return buffer.get() & 0xFF; } @Override public int read(byte[] bytes, int off, int len) throws IOException { if (!buffer.hasRemaining()) { return -1; } len = Math.min(len, buffer.remaining()); buffer.get(bytes, off, len); return len; } } class MappedByteBufferOutputStream extends OutputStream { private final MappedByteBuffer buffer; public MappedByteBufferOutputStream(MappedByteBuffer buffer) { this.buffer = buffer; } @Override public void write(int b) throws IOException { buffer.put((byte) b); } @Override public void write(byte[] bytes, int off, int len) throws IOException { buffer.put(bytes, off, len); } } ``` and then use: ``` try (MappedByteBufferInputStream mbbis = new MappedByteBufferInputStream(buffer); DataInputStream is = new DataInputStream(mbbis)) { // Read data using DataInputStream } try (MappedByteBufferOutputStream mbbos = new MappedByteBufferOutputStream(buffer); DataOutputStream os = new DataOutputStream(mbbos)) { // Write data using DataOutputStream } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org