public void write(byte[] b, int off, int len) { if (_overflow == null) { while (len > 0) { Block s = last(); if (s.isFull()) { if (reachedInCoreLimit()) break; s = new Block(); _blocks.Add(s); } int n = Math.Min(Block.SZ - s.count, len); Array.Copy(b, off, s.buffer, s.count, n); s.count += n; len -= n; off += n; } } if (len > 0) _overflow.Write(b, off, len); }
/// <summary> /// Copy all bytes remaining on the input stream into this buffer. /// </summary> /// <param name="in">the stream to Read from, until EOF is reached.</param> public void copy(Stream @in) { if (@in == null) throw new ArgumentNullException("in"); if (_blocks != null) { for (; ; ) { Block s = last(); if (s.isFull()) { if (reachedInCoreLimit()) break; s = new Block(); _blocks.Add(s); } int n = @in.Read(s.buffer, s.count, Block.SZ - s.count); if (n < 1) return; s.count += n; } } byte[] tmp = new byte[Block.SZ]; int nn; while ((nn = @in.Read(tmp, 0, tmp.Length)) > 0) _overflow.Write(tmp, 0, nn); }
public void write(int b) { if (_overflow != null) { _overflow.WriteByte((byte)b); return; } Block s = last(); if (s.isFull()) { if (reachedInCoreLimit()) { _overflow.WriteByte((byte)b); return; } s = new Block(); _blocks.Add(s); } s.buffer[s.count++] = (byte)b; }
/** * Copy all bytes remaining on the input stream into this buffer. * * @param in * the stream to Read from, until EOF is reached. * @ * an error occurred reading from the input stream, or while * writing to a local temporary file. */ public void copy(Stream @in) { if (_blocks != null) { for (; ; ) { Block s = last(); if (s.isFull()) { if (reachedInCoreLimit()) break; s = new Block(); _blocks.Add(s); } int n = @in.Read(s.buffer, s.count, Block.SZ - s.count); if (n < 1) return; s.count += n; } } byte[] tmp = new byte[Block.SZ]; int nn; while ((nn = @in.Read(tmp, 0, tmp.Length)) > 0) diskOut.Write(tmp, 0, nn); }