writeBuf() public method

public writeBuf ( Buf buf ) : OutStream
buf Buf
return OutStream
Ejemplo n.º 1
0
 public virtual long pipe(OutStream output, Long toPipe, bool cls)
 {
     try
     {
         long bufSize = FanInt.Chunk.longValue();
         Buf  buf     = Buf.make(bufSize);
         long total   = 0;
         if (toPipe == null)
         {
             while (true)
             {
                 Long n = readBuf(buf.clear(), bufSize);
                 if (n == null)
                 {
                     break;
                 }
                 output.writeBuf(buf.flip(), buf.remaining());
                 total += n.longValue();
             }
         }
         else
         {
             long toPipeVal = toPipe.longValue();
             while (total < toPipeVal)
             {
                 if (toPipeVal - total < bufSize)
                 {
                     bufSize = toPipeVal - total;
                 }
                 Long n = readBuf(buf.clear(), bufSize);
                 if (n == null)
                 {
                     throw IOErr.make("Unexpected end of stream").val;
                 }
                 output.writeBuf(buf.flip(), buf.remaining());
                 total += n.longValue();
             }
         }
         return(total);
     }
     finally
     {
         if (cls)
         {
             close();
         }
     }
 }
Ejemplo n.º 2
0
 public virtual long pipe(OutStream output, Long toPipe, bool cls)
 {
     try
       {
     long bufSize = FanInt.Chunk.longValue();
     Buf buf = Buf.make(bufSize);
     long total = 0;
     if (toPipe == null)
     {
       while (true)
       {
     Long n = readBuf(buf.clear(), bufSize);
     if (n == null) break;
     output.writeBuf(buf.flip(), buf.remaining());
     total += n.longValue();
       }
     }
     else
     {
       long toPipeVal = toPipe.longValue();
       while (total < toPipeVal)
       {
     if (toPipeVal - total < bufSize) bufSize = toPipeVal - total;
     Long n = readBuf(buf.clear(), bufSize);
     if (n == null) throw IOErr.make("Unexpected end of stream").val;
     output.writeBuf(buf.flip(), buf.remaining());
     total += n.longValue();
       }
     }
     return total;
       }
       finally
       {
     if (cls) close();
       }
 }