hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupOutputStream.java
@Override
  public synchronized void write(byte[] b, int off, int len)
      throws IOException {
    checkNotClosed();

    if (b == null) {
      throw new NullPointerException();
    }
    if ((off < 0) || (off > b.length) || (len < 0) ||
        ((off + len) > b.length) || ((off + len) < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
      return;
    }
    int succeededAllocates = 0;
    while (len > 0) {
      if (streamEntries.size() <= currentStreamIndex) {
        Preconditions.checkNotNull(ksmClient);
        // allocate a new block, if a exception happens, log an error and
        // throw exception to the caller directly, and the write fails.
        try {
          allocateNewBlock(currentStreamIndex);
          succeededAllocates += 1;
        } catch (IOException ioe) {
          LOG.error("Try to allocate more blocks for write failed, already " +
              "allocated " + succeededAllocates + " blocks for this write.");
          throw ioe;
        }
      }
      // in theory, this condition should never violate due the check above
      // still do a sanity check.
      Preconditions.checkArgument(currentStreamIndex < streamEntries.size());
      ChunkOutputStreamEntry current = streamEntries.get(currentStreamIndex);
      int writeLen = Math.min(len, (int)current.getRemaining());
      current.write(b, off, writeLen);
      if (current.getRemaining() <= 0) {
        currentStreamIndex += 1;
      }
      len -= writeLen;
      off += writeLen;
      byteOffset += writeLen;
    }
  }
/**
   * Try to write the bytes sequence b[off:off+len) to streams.
   *
   * NOTE: Throws exception if the data could not fit into the remaining space.
   * In which case nothing will be written.
   * TODO:May need to revisit this behaviour.
   *
   * @param b byte data
   * @param off starting offset
   * @param len length to write
   * @throws IOException
   */
Try to write the bytes sequence b[off:off+len) to streams.
NOTE: Throws exception if the data could not fit into the remaining space.
In which case nothing will be written.
TODO:May need to revisit this behaviour.

@param b byte data
@param off starting offset
@param len length to write
@throws IOException
Try to write the bytes sequence b [ off : off + len ) to streams . NOTE : Throws exception if the data could not fit into the remaining space . In which case nothing will be written . TODO : May need to revisit this behaviour . @param b byte data @param off starting offset @param len length to write @throws IOException
@Override
  public synchronized void write(byte[] b, int off, int len)
      throws IOException {
    checkNotClosed();
    if (b == null) {
      throw new NullPointerException();
    }
    if ((off < 0) || (off > b.length) || (len < 0) ||
        ((off + len) > b.length) || ((off + len) < 0)) {
      throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
      return;
    }
    int succeededAllocates = 0;
    while (len > 0) {
      if (streamEntries.size() <= currentStreamIndex) {
        Preconditions.checkNotNull(ksmClient);
        try {
          allocateNewBlock(currentStreamIndex);
          succeededAllocates += 1;
        } catch (IOException ioe) {
          LOG.error("Try to allocate more blocks for write failed, already " +
              "allocated " + succeededAllocates + " blocks for this write.");
          throw ioe;
        }
      }
      Preconditions.checkArgument(currentStreamIndex < streamEntries.size());
      ChunkOutputStreamEntry current = streamEntries.get(currentStreamIndex);
      int writeLen = Math.min(len, (int)current.getRemaining());
      current.write(b, off, writeLen);
      if (current.getRemaining() <= 0) {
        currentStreamIndex += 1;
      }
      len -= writeLen;
      off += writeLen;
      byteOffset += writeLen;
    }
  }
@ Override public synchronized void write ( byte [ ] b , int off , int len ) throws IOException { checkNotClosed ( ) ; if ( b == null ) { throw new NullPointerException ( ) ; } if ( ( off < 0 ) || ( off > b . length ) || ( len < 0 ) || ( ( off + len ) > b . length ) || ( ( off + len ) < 0 ) ) { throw new IndexOutOfBoundsException ( ) ; } if ( len == 0 ) { return ; } int succeededAllocates = 0 ; while ( len > 0 ) { if ( streamEntries . size ( ) <= currentStreamIndex ) { Preconditions . checkNotNull ( ksmClient ) ; try { allocateNewBlock ( currentStreamIndex ) ; succeededAllocates += 1 ; } catch ( IOException ioe ) { LOG . error ( "Try to allocate more blocks for write failed, already " + "allocated " + succeededAllocates + " blocks for this write." ) ; throw ioe ; } } Preconditions . checkArgument ( currentStreamIndex < streamEntries . size ( ) ) ; ChunkOutputStreamEntry current = streamEntries . get ( currentStreamIndex ) ; int writeLen = Math . min ( len , ( int ) current . getRemaining ( ) ) ; current . write ( b , off , writeLen ) ; if ( current . getRemaining ( ) <= 0 ) { currentStreamIndex += 1 ; } len -= writeLen ; off += writeLen ; byteOffset += writeLen ; } }
Try to write the bytes sequence b[off:off+len) to streams.
Try to write the bytes sequence b [ off : off + len ) to streams .
// allocate a new block, if a exception happens, log an error and // throw exception to the caller directly, and the write fails. // in theory, this condition should never violate due the check above // still do a sanity check.