diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/Document.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/Document.java index cadbbdac5..0e85555dc 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/Document.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/Document.java @@ -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; @@ -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; @@ -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;