driver-legacy/src/main/com/mongodb/gridfs/GridFSInputFile.java
public int saveChunks(final long chunkSize) throws IOException {
        if (outputStream != null) {
            throw new MongoException("Cannot mix OutputStream and regular save()");
        }
        if (savedChunks) {
            throw new MongoException("Chunks already saved!");
        }

        if (chunkSize <= 0) {
            throw new MongoException("chunkSize must be greater than zero");
        }

        if (this.chunkSize != chunkSize) {
            this.chunkSize = chunkSize;
            buffer = new byte[(int) this.chunkSize];
        }

        int bytesRead = 0;
        while (bytesRead >= 0) {
            currentBufferPosition = 0;
            bytesRead = _readStream2Buffer();
            dumpBuffer(true);
        }

        // only finish data, do not write file, in case one wants to change metadata
        finishData();
        return currentChunkNumber;
    }
public int saveChunks(final long chunkSize) throws IOException {
        if (outputStream != null) {
            throw new MongoException("Cannot mix OutputStream and regular save()");
        }
        if (savedChunks) {
            throw new MongoException("Chunks already saved!");
        }

        if (chunkSize <= 0) {
            throw new MongoException("chunkSize must be greater than zero");
        }

        if (this.chunkSize != chunkSize) {
            this.chunkSize = chunkSize;
            buffer = new byte[(int) this.chunkSize];
        }

        int bytesRead = 0;
        while (bytesRead >= 0) {
            currentBufferPosition = 0;
            bytesRead = _readStream2Buffer();
            dumpBuffer(true);
        }

        // only finish data, do not write file, in case one wants to change metadata
        finishData();
        return currentChunkNumber;
    }
public int saveChunks ( final long chunkSize ) throws IOException { if ( outputStream != null ) { throw new MongoException ( "Cannot mix OutputStream and regular save()" ) ; } if ( savedChunks ) { throw new MongoException ( "Chunks already saved!" ) ; } if ( chunkSize <= 0 ) { throw new MongoException ( "chunkSize must be greater than zero" ) ; } if ( this . chunkSize != chunkSize ) { this . chunkSize = chunkSize ; buffer = new byte [ ( int ) this . chunkSize ] ; } int bytesRead = 0 ; while ( bytesRead >= 0 ) { currentBufferPosition = 0 ; bytesRead = _readStream2Buffer ( ) ; dumpBuffer ( true ) ; } // only finish data, do not write file, in case one wants to change metadata finishData ( ) ; return currentChunkNumber ; }
Saves all data into chunks from configured {@link java.io.InputStream} input stream to GridFS. A non-default chunk size can be
specified. This method does NOT save the file object itself, one must call save() to do so.

@param chunkSize Size of chunks for file in bytes.
@return Number of the next chunk.
@throws IOException    on problems reading the new entry's {@link java.io.InputStream}.
@throws MongoException if there's a failure
Saves all data into chunks from configured { @link java . io . InputStream } input stream to GridFS . A non - default chunk size can be specified . This method does NOT save the file object itself one must call save () to do so .