code: public void update(InputStream stream, long length, long position) throws IOException, RepositoryException
     {
        validateAndAdjustLenght(length, position, Integer.MAX_VALUE);
  
        long newSize = Math.max(length + position, value.length);
        byte[] newBytes = new byte[(int)newSize];
  
        if (position > 0)
        {
           // begin from the existed bytes
           System.arraycopy(value, 0, newBytes, 0, (int)(position < value.length ? position : value.length));
        }
  
        // write new data
        long read;
        boolean doRead = true;
        byte[] buff = new byte[2048];
  
        while (doRead && (read = stream.read(buff)) >= 0)
        {
           if (position + read > newBytes.length)
           {
              // given length reached
              read = newBytes.length - position;
              doRead = false;
           }
           System.arraycopy(buff, 0, newBytes, (int)position, (int)read);
           position += read;
        }
  
        if (position < value.length)
        {
           // write the rest of existed data
           System.arraycopy(value, (int)position, newBytes, (int)position, (int)(value.length - position));
        }
  
        value = newBytes;
     }
docs: {@inheritDoc}