X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Futil%2FIO.java;fp=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Futil%2FIO.java;h=6e7b4824be22601a12e1cfbfb36f808681597e17;hp=51fbed94db4978d02d0187f2d62036d55f7dfc59;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=875b5e9651498a0cd8e0001c0742ba843e47cad0 diff --git a/lib/jetty/org/eclipse/jetty/util/IO.java b/lib/jetty/org/eclipse/jetty/util/IO.java index 51fbed94..6e7b4824 100644 --- a/lib/jetty/org/eclipse/jetty/util/IO.java +++ b/lib/jetty/org/eclipse/jetty/util/IO.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 @@ -29,6 +29,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; @@ -366,7 +369,8 @@ public class IO { if (writer != null) writer.close(); - } catch (IOException e) + } + catch (IOException e) { LOG.ignore(e); } @@ -380,6 +384,52 @@ public class IO copy(in,bout); return bout.toByteArray(); } + + /* ------------------------------------------------------------ */ + /** + * A gathering write utility wrapper. + *

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