code: public int write(byte[] data, int offset, int count) throws IOException {
      int result = count;
      try {
        fos.write(data,offset,count);
        if(position + count > size)
          size = position+count;
        position+= count;
      }catch(IOException e) {
        throw e;
      }
      return result;
    }
docs: Write the given number of bytes from the byte array. Return number of
  bytes written.
  @param data array containing bytes to be written.
  @param offset start index of array to begin reading from.
  @param count number of bytes to write.
  @return number of bytes written.
  @throws IOException IOException upon a write error.