Skip to content

Commit

Permalink
GH-323 a memory intensive try at fixing a windows/jdk file lock issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Corless committed Dec 7, 2023
1 parent 9851759 commit 57be4bc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions core/core-awt/src/main/java/org/icepdf/core/pobjects/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ public void setFile(String filepath)
try {
randomAccessFile = new RandomAccessFile(file, "r");
documentFileChannel = randomAccessFile.getChannel();
ByteBuffer mappedFileByteBuffer = documentFileChannel.map(
FileChannel.MapMode.READ_ONLY, 0, documentFileChannel.size());
setInputStream(mappedFileByteBuffer);
long fileSize = documentFileChannel.size();
// Create an in memory file opy
ByteBuffer buffer = ByteBuffer.allocate((int) fileSize);
documentFileChannel.read(buffer);
buffer.flip();
setInputStream(buffer);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to set document file path", e);
throw e;
Expand Down Expand Up @@ -271,9 +274,12 @@ public void setInputStream(InputStream inputStream, String pathOrURL)
try {
randomAccessFile = new RandomAccessFile(tempFile, "r");
documentFileChannel = randomAccessFile.getChannel();
ByteBuffer mappedFileByteBuffer = documentFileChannel.map(
FileChannel.MapMode.READ_ONLY, 0, documentFileChannel.size());
setInputStream(mappedFileByteBuffer);
long fileSize = documentFileChannel.size();
// Create an in memory file opy
ByteBuffer buffer = ByteBuffer.allocate((int) fileSize);
documentFileChannel.read(buffer);
buffer.flip();
setInputStream(buffer);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to set document input stream", e);
throw e;
Expand Down Expand Up @@ -327,9 +333,12 @@ public void setByteArray(byte[] data, int offset, int length, String pathOrURL)
try {
randomAccessFile = new RandomAccessFile(tempFile, "r");
documentFileChannel = randomAccessFile.getChannel();
ByteBuffer mappedFileByteBuffer = documentFileChannel.map(
FileChannel.MapMode.READ_ONLY, 0, documentFileChannel.size());
setInputStream(mappedFileByteBuffer);
long fileSize = documentFileChannel.size();
// Create an in memory file opy
ByteBuffer buffer = ByteBuffer.allocate((int) fileSize);
documentFileChannel.read(buffer);
buffer.flip();
setInputStream(buffer);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to set document input stream", e);
throw e;
Expand Down

0 comments on commit 57be4bc

Please sign in to comment.