Writes the current checksum to a buffer.
If <i>reset</i> is true, then resets the checksum.
@return number of bytes written. Will be equal to getChecksumSize();
191796
public int writeValue( byte[] buf, int offset, boolean reset )
                           throws IOException {
      if ( size <= 0 ) {
        return 0;
      }

      if ( size == 4 ) {
        int checksum = (int) summer.getValue();
        writeIntToBuf(checksum, buf, offset);
      } else {
        throw new IOException( "Unknown Checksum " + type );
      }
      
      if ( reset ) {
        reset();
      }
      
      return size;
    }
405955
public static int writeBytes(final BitOutput bitOutput, final int lengthSize, final boolean byteUnsigned,
                                 final int byteSize, final byte[] value)
            throws IOException {
        if (bitOutput == null) {
            throw new NullPointerException("bitOutput is null");
        }
        requireValidSizeInt(true, lengthSize);
        requireValidSizeByte(byteUnsigned, byteSize);
        if (value == null) {
            throw new NullPointerException("value is null");
        }
        final int length = value.length & ((1 << lengthSize) - 1);
        bitOutput.writeInt(true, lengthSize, length);
        for (int i = 0; i < length; i++) {
            bitOutput.writeByte(byteUnsigned, byteSize, value[i]);
        }
        return length;
    }
848232
@Override
	public int writeBit(int bit) throws BitStreamException {
		//TODO what is the correct behaviour here?
		//throw EOBSE or return reduced count
		if (position + bufferSize + 1 > size) throw new BitStreamException("array full");

		if (bufferSize == 0) {
			bufferBits = bit;
			bufferSize = 1;
		} else if (bufferSize + 1 <= 32) {
			bufferBits = (bufferBits << 1) | bit & 1;
			bufferSize ++;
		} else {
			flushBuffer();
			bufferBits = bit;
			bufferSize = 1;

		}

		return 1;
	}
709401
private static String getDumpBytes(WsByteBuffer buffer, int bytesToDump, boolean rewind)
   {
      // Save the current position
      int pos = buffer.position();
      if (rewind)
      {
         buffer.rewind();
      }

      byte[] data = null;
      int start;
      int count = bytesToDump;
      if (count > buffer.remaining() || count == ENTIRE_BUFFER) count = buffer.remaining();

      if (buffer.hasArray())
      {
         data = buffer.array();
         start = buffer.arrayOffset() + buffer.position();
      }
      else
      {
         data = new byte[count];
         buffer.get(data);
         start = 0;
      }

      String strData = "Dumping "+count+" bytes of buffer data:\r\n";
      if (count > 0) strData += SibTr.formatBytes(data, start, count);

      // Return the position to where it should be
      if (rewind) buffer.position(pos);

      return strData;
   }
134780
private int ensureBuffer(int offset, int length) throws IOException {
		final int lastPos = offset + length - 1;
		final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE;
		final int currentSize = this.buffer.length;

		if (desiredSize > currentSize) {
			final byte[] readBuffer = new byte[desiredSize - currentSize];
			final int count = this.in.read(readBuffer);

			if (count > 0) {
				final byte[] newBuffer = new byte[currentSize + count];
				System.arraycopy(this.buffer, 0, newBuffer, 0, currentSize);
				System.arraycopy(readBuffer, 0, newBuffer, currentSize, count);
				this.buffer = newBuffer;
			}
			return (lastPos < this.buffer.length) ? length : length - (lastPos - this.buffer.length + 1);
		}
		return length;
	}
617665
@Override
  public void write (@Nonnull final byte [] b) throws IOException
  {
    checkThreshold (b.length);
    getStream ().write (b);
    m_nWritten += b.length;
  }
273298
public void writeBytes(byte[] buffer)
        throws IOException
    {
        if (buffer == null) {
            if (SIZE < _offset + 16)
                flushBuffer();

            _buffer[_offset++] = 'N';
        }
        else
            writeBytes(buffer, 0, buffer.length);
    }
706001
@Override
    public void write(byte[] b, int off, int len) throws IOException {
        if (currentEntry != null && !currentEntry.isDirectory()) {
            if (currentEntry.getSize() < currentFileSize + len) {
                throw new IOException( "The current entry[" + currentEntry.getName() + "] size["
                        + currentEntry.getSize() + "] is smaller than the bytes[" + ( currentFileSize + len )
                        + "] being written." );
            }
        }

        out.write( b, off, len );
        
        bytesWritten += len;

        if (currentEntry != null) {
            currentFileSize += len;
        }        
    }
1216034
public byte checksum() {
    if(DEBUG_LEV > 10 )
      System.err.println("CRC8::checksum : Begin");
    //add 8 to the count,
    //call update with a byte constructed to add no more.
    //byte[] fake = {0};
    workingCRC8Count += 8;
    byte val = updateCRC8(fake, 0, 1);
    if(DEBUG_LEV > 10 )
      System.err.println("CRC8::checksum : End");
    return val;
  }
526581
public ByteBuffer frameAndReturnBuffer ()
    {
        // flip the buffer which will limit it to its current position
        _buffer.flip();

        // then write the frame length and rewind back to the start of the
        // buffer so that all the data is available
        int count = _buffer.limit();
        _buffer.put((byte)((count >>> 24) & 0xFF));
        _buffer.put((byte)((count >>> 16) & 0xFF));
        _buffer.put((byte)((count >>>  8) & 0xFF));
        _buffer.put((byte)((count >>>  0) & 0xFF));
        _buffer.rewind();

        return _buffer;
    }
1149339
private int fillBuffer() throws IOException {
    int cnt = 0;
    int rem = this.buff_.length;
    while (rem > 0) {
      int n = super.read(this.buff_, cnt, rem);
      if (n < 0) {
        break;
      }
      cnt += n;
      rem -= n;
    }
    if ((cnt < 0) && (this.hitEOF_ = (cnt < this.buff_.length))) {
      // make sure buffer that wasn't read is initialized with -1
      Arrays.fill(this.buff_, cnt, this.buff_.length, (byte) 0xff);
    }
    this.diskPos_ += cnt;
    return cnt;
  }
38659
private java.nio.ByteBuffer getWritingRow() {
        final int row = this.writerIndex / this.localCapacity;
        if (row >= this.storage.size()) {
            final java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(this.localCapacity);
            this.storage.add(buf);
            return buf;
        }

        return this.storage.get(row);
    }
666228
@Override
  public void write(byte []buffer, int offset, int length)
  {
    if (isClosed() || isHead()) {
      return;
    }

    int byteLength = _offset;
    
    while (true) {
      int sublen = Math.min(length, SIZE - byteLength);

      System.arraycopy(buffer, offset, _buffer, byteLength, sublen);
      offset += sublen;
      length -= sublen;
      byteLength += sublen;
      
      if (length <= 0) {
        break;
      }
      
      _offset = byteLength;
      flushByteBuffer();
      byteLength = _offset;
    }

    _offset = byteLength;
  }
183581
def _finalize_write(self):
        ''

        # Make sure we have written the header
        if not self._done_header:
            self._write_header()

        # Write the remaining decrypted part to disk
        block = self._crypto.encrypt(self._decrypted_buffer)
        self._decrypted = ''
        self._fp.write(block)
        self._checksumer.update(block)

        # Write the final checksum
        self._fp.write(self._checksumer.digest())
        self._valid = True
29334
private static byte calculateChecksum(byte[] buffer) {
		byte checkSum = (byte)0xFF;
		for (int i=1; i<buffer.length-1; i++) {
			checkSum = (byte) (checkSum ^ buffer[i]);
		}
		logger.trace(String.format("Calculated checksum = 0x%02X", checkSum));
		return checkSum;
	}
471797
def checksum(self):
        
        total = 0

        # Add together all bytes
        for byte in self.data:
            total += byteToInt(byte)

        # Only keep the last byte
        total = total & 0xFF

        return intToByte(0xFF - total)
1086185
@Override
  public void write (final int b) throws IOException
  {
    if (m_nCount >= m_aBuf.length)
      _flushBuffer ();
    m_aBuf[m_nCount++] = (byte) b;
  }