Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-07-23 01:34:59 +0000
committerGreg Wilkins2015-07-23 01:34:59 +0000
commite1faa5c1e920ee4071c5dc2dab575b9452b4f625 (patch)
tree12717b50c397303b10ec368c878741e7aa1f3dcd /jetty-util
parent7686a19db9121c048644908db69e63e99da17ea9 (diff)
parentac8316756c53e7c2be8b81fa1ecb4f35dabd576e (diff)
downloadorg.eclipse.jetty.project-e1faa5c1e920ee4071c5dc2dab575b9452b4f625.tar.gz
org.eclipse.jetty.project-e1faa5c1e920ee4071c5dc2dab575b9452b4f625.tar.xz
org.eclipse.jetty.project-e1faa5c1e920ee4071c5dc2dab575b9452b4f625.zip
Merge remote-tracking branch 'origin/jetty-9.2.x'
Conflicts: jetty-util/src/main/java/org/eclipse/jetty/util/IO.java jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java
Diffstat (limited to 'jetty-util')
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/IO.java52
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java15
2 files changed, 66 insertions, 1 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
index f89068a489..355936b0d9 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
@@ -30,6 +30,9 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.GatheringByteChannel;
import java.nio.charset.Charset;
import org.eclipse.jetty.util.log.Log;
@@ -415,9 +418,55 @@ public class IO
copy(in,bout);
return bout.toByteArray();
}
-
+
/* ------------------------------------------------------------ */
/**
+ * A gathering write utility wrapper.
+ * <p>This method wraps a gather write with a loop that handles the limitations of some operating systems that
+ * have a limit on the number of buffers written. The method loops on the write until either all the content
+ * is written or no progress is made.
+ * @param out The GatheringgByteChannel to write to
+ * @param buffers The buffers to write
+ * @param offset The offset into the buffers array
+ * @param length The length in buffers to write
+ * @return The total bytes written
+ * @throws IOException
+ */
+ public static long write(GatheringByteChannel out, ByteBuffer[] buffers, int offset, int length) throws IOException
+ {
+ long total=0;
+ write: while (length>0)
+ {
+ // Write as much as we can
+ long wrote=out.write(buffers,offset,length);
+
+ // If we can't write any more, give up
+ if (wrote==0)
+ break;
+
+ // count the total
+ total+=wrote;
+
+ // Look for unwritten content
+ for (int i=offset;i<buffers.length;i++)
+ {
+ if (buffers[i].hasRemaining())
+ {
+ // loop with new offset and length;
+ length=length-(i-offset);
+ offset=i;
+ continue write;
+ }
+ }
+ length=0;
+ }
+
+ return total;
+ }
+
+
+ /* ------------------------------------------------------------ */
+ /**
* @return An outputstream to nowhere
*/
public static OutputStream getNullStream()
@@ -503,6 +552,7 @@ public class IO
}
private static NullWrite __nullWriter = new NullWrite();
private static PrintWriter __nullPrintWriter = new PrintWriter(__nullWriter);
+
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java
index 89c600c50c..33258d0e1d 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java
@@ -187,6 +187,21 @@ public class ResourceTest
return bdata;
}
}
+
+ /* ------------------------------------------------------------ */
+ @Test
+ public void testEncodeAddPath ()
+ throws Exception
+ {
+ Resource r;
+
+ r = Resource.newResource(__userURL+"TestData/").addPath("foo%/b r");
+ Assert.assertThat(r.getURI().toString(),Matchers.endsWith("/foo%25/b%20r"));
+
+ r = Resource.newResource("jar:"+__userURL+"TestData/test.zip!/subdir/").addPath("foo%/b r");
+ Assert.assertThat(r.getURI().toString(),Matchers.endsWith("/foo%25/b%20r"));
+ }
+
@Parameters(name="{0}")

Back to the top