Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-12-18 01:50:19 +0000
committerGreg Wilkins2015-12-18 01:50:19 +0000
commit133e9e054d1a6a3a16eb602cbdfd3f86f3c87572 (patch)
tree57c58d6dcffac4147ca4b5310866e0013249209a /jetty-util/src/main/java
parent316a2e866190c90e4dc4fc37c99ccce04ad57c6f (diff)
parent5cd676581c178dc3611298e611c62fc51ed1b6cf (diff)
downloadorg.eclipse.jetty.project-133e9e054d1a6a3a16eb602cbdfd3f86f3c87572.tar.gz
org.eclipse.jetty.project-133e9e054d1a6a3a16eb602cbdfd3f86f3c87572.tar.xz
org.eclipse.jetty.project-133e9e054d1a6a3a16eb602cbdfd3f86f3c87572.zip
Merge remote-tracking branch 'origin/jetty-9.3.x'
Conflicts: jetty-security/src/main/java/org/eclipse/jetty/security/HashLoginService.java
Diffstat (limited to 'jetty-util/src/main/java')
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java45
1 files changed, 43 insertions, 2 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
index 49377144e1..fa1ef983ab 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
@@ -19,17 +19,21 @@
package org.eclipse.jetty.util;
import java.io.File;
+import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
+import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import org.eclipse.jetty.util.log.Log;
@@ -903,12 +907,48 @@ public class BufferUtil
public static ByteBuffer toMappedBuffer(File file) throws IOException
{
- try (RandomAccessFile raf = new RandomAccessFile(file, "r"))
+ try (FileChannel channel = FileChannel.open(file.toPath(),StandardOpenOption.READ))
{
- return raf.getChannel().map(MapMode.READ_ONLY, 0, raf.length());
+ return channel.map(MapMode.READ_ONLY, 0, file.length());
}
}
+ static final Field fdMappedByteBuffer;
+ static
+ {
+ Field fd = null;
+ try
+ {
+ fd=MappedByteBuffer.class.getDeclaredField("fd");
+ fd.setAccessible(true);
+ }
+ catch(Exception e)
+ {
+ }
+ fdMappedByteBuffer=fd;
+ }
+
+ public static boolean isMappedBuffer(ByteBuffer buffer)
+ {
+ if (!(buffer instanceof MappedByteBuffer))
+ return false;
+ MappedByteBuffer mapped = (MappedByteBuffer) buffer;
+
+ if (fdMappedByteBuffer!=null)
+ {
+ try
+ {
+ if (fdMappedByteBuffer.get(mapped) instanceof FileDescriptor)
+ return true;
+ }
+ catch(Exception e)
+ {
+ }
+ }
+ return false;
+ }
+
+
public static ByteBuffer toBuffer(Resource resource,boolean direct) throws IOException
{
int len=(int)resource.length();
@@ -1156,4 +1196,5 @@ public class BufferUtil
+
}

Back to the top