dap4/d4servlet/src/main/java/dap4/servlet/ChunkWriter.java
@Override
    public void write(byte[] b, int off, int len)
            throws IOException
    {
        verifystate();
        if(writecount + len >= writelimit)
            throw new DapException("Attempt to write too much data: limit=" + writecount + len)
                    .setCode(DapCodes.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
        if(chunk == null)
            chunk = ByteBuffer.allocate(maxbuffersize).order(getWriteOrder());
        if(state == State.DMR) {
            chunk.clear(); // reset
            state = State.DATA;
        }
        assert (state == State.DATA);
        if(b.length < off + len)
            throw new BufferUnderflowException();
        int left = len;
        int offset = off;
        while(left > 0) {
            int avail = chunk.remaining();
            do {
                if(avail == 0) {
                    writeChunk(DapUtil.CHUNK_DATA);
                    avail = chunk.remaining();
                }
                int towrite = (left < avail ? left : avail);
                chunk.put(b, off, towrite);
                left -= towrite;
                avail -= towrite;
            } while(left > 0);
        }
        writecount += len;
    }
@Override
    public void write(byte[] b, int off, int len)
            throws IOException
    {
        verifystate();
        if(writecount + len >= writelimit)
            throw new DapException("Attempt to write too much data: limit=" + writecount + len)
                    .setCode(DapCodes.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
        if(chunk == null)
            chunk = ByteBuffer.allocate(maxbuffersize).order(getWriteOrder());
        if(state == State.DMR) {
            chunk.clear(); // reset
            state = State.DATA;
        }
        assert (state == State.DATA);
        if(b.length < off + len)
            throw new BufferUnderflowException();
        int left = len;
        int offset = off;
        while(left > 0) {
            int avail = chunk.remaining();
            do {
                if(avail == 0) {
                    writeChunk(DapUtil.CHUNK_DATA);
                    avail = chunk.remaining();
                }
                int towrite = (left < avail ? left : avail);
                chunk.put(b, off, towrite);
                left -= towrite;
                avail -= towrite;
            } while(left > 0);
        }
        writecount += len;
    }
@ Override public void write ( byte [ ] b , int off , int len ) throws IOException { verifystate ( ) ; if ( writecount + len >= writelimit ) throw new DapException ( "Attempt to write too much data: limit=" + writecount + len ) . setCode ( DapCodes . SC_REQUESTED_RANGE_NOT_SATISFIABLE ) ; if ( chunk == null ) chunk = ByteBuffer . allocate ( maxbuffersize ) . order ( getWriteOrder ( ) ) ; if ( state == State . DMR ) { chunk . clear ( ) ; // reset state = State . DATA ; } assert ( state == State . DATA ) ; if ( b . length < off + len ) throw new BufferUnderflowException ( ) ; int left = len ; int offset = off ; while ( left > 0 ) { int avail = chunk . remaining ( ) ; do { if ( avail == 0 ) { writeChunk ( DapUtil . CHUNK_DATA ) ; avail = chunk . remaining ( ) ; } int towrite = ( left < avail ? left : avail ) ; chunk . put ( b , off , towrite ) ; left -= towrite ; avail -= towrite ; } while ( left > 0 ) ; } writecount += len ; }
Writes len bytes from the specified byte array starting at
offset off to this output stream.
<p>
If this write fills up the chunk buffer,
then write out the buffer and put
the remaining bytes into the reset buffer.

@param b   the data
@param off start point in b from which to write data
@param len number of bytes to write
@throws IOException if an I/O error occurs
Writes len bytes from the specified byte array starting at offset off to this output stream . <p > If this write fills up the chunk buffer then write out the buffer and put the remaining bytes into the reset buffer .