code: private synchronized void write(WritableByteChannel channel,
              Collection<MLArray> data) throws IOException
      {
          try
          {
              //write header
              writeHeader(channel);
  
              //write data
              for ( MLArray matrix : data )
              {
                  //compress data to save storage
                  Deflater compresser = new Deflater();
  
                  ByteArrayOutputStream2 compressed = new ByteArrayOutputStream2();
                  DataOutputStream dout = new DataOutputStream(new DeflaterOutputStream(compressed, compresser));
  
                  writeMatrix( dout, matrix );
                  dout.flush();
                  dout.close();
  
                  //write COMPRESSED tag and compressed data into output channel
  
                  int compressedSize = compressed.getCount();
                  ByteBuffer buf = ByteBuffer.allocateDirect(2 * 4 /* Int size */ + compressedSize);
                  buf.putInt( MatDataTypes.miCOMPRESSED );
  
                  buf.putInt( compressedSize);
                  buf.put(compressed.getBuf(), 0, compressedSize);
  
                  buf.flip();
                  channel.write( buf );
              }
          }
          catch ( IOException e )
          {
              throw e;
          }
          finally
          {
              channel.close();
          }
      }
docs: Writes <code>MLArrays</code> into <code>WritableByteChannel</code>.
  
  @param channel
  the channel to write to
  @param data
  the collection of <code>{@link MLArray}</code> objects
  @throws IOException
  if writing fails