cdm/src/main/java/ucar/nc2/iosp/cinrad/Cinrad2VolumeScan.java
private RandomAccessFile uncompress(RandomAccessFile raf2, String ufilename, boolean debug) throws IOException {
    raf2.seek(0);
    byte[] header = new byte[Cinrad2Record.FILE_HEADER_SIZE];
    int bytesRead = raf2.read(header);
    if (bytesRead != header.length) {
      throw new IOException("Error reading CINRAD header -- got " +
              bytesRead + " rather than" + header.length);
    }
    RandomAccessFile dout2 = new RandomAccessFile(ufilename, "rw");

    boolean eof = false;
    int numCompBytes;
    byte[] ubuff = new byte[40000];
    byte[] obuff = new byte[40000];
    try {
      dout2.write(header);
      CBZip2InputStream cbzip2 = new CBZip2InputStream();
      while (!eof) {

        try {
          numCompBytes = raf2.readInt();
          if (numCompBytes == -1) {
            if (debug) log.debug("  done: numCompBytes=-1 ");
            break;
          }
        } catch (EOFException ee) {
          if (debug) log.debug("  got EOFException ");
          break; // assume this is ok
        }

        if (debug) {
          log.debug("reading compressed bytes " + numCompBytes + " input starts at " + raf2.getFilePointer() + "; output starts at " + dout2.getFilePointer());
        }
        /*
        * For some stupid reason, the last block seems to
        * have the number of bytes negated.  So, we just
        * assume that any negative number (other than -1)
        * is the last block and go on our merry little way.
        */
        if (numCompBytes < 0) {
          if (debug) log.debug("last block?" + numCompBytes);
          numCompBytes = -numCompBytes;
          eof = true;
        }
        byte[] buf = new byte[numCompBytes];
        raf2.readFully(buf);
        ByteArrayInputStream bis = new ByteArrayInputStream(buf, 2, numCompBytes - 2);

        //CBZip2InputStream cbzip2 = new CBZip2InputStream(bis);
        cbzip2.setStream(bis);
        int total = 0;
        int nread;
        /*
        while ((nread = cbzip2.read(ubuff)) != -1) {
          dout2.write(ubuff, 0, nread);
          total += nread;
        }
        */
        try {
          while ((nread = cbzip2.read(ubuff)) != -1) {
            if (total + nread > obuff.length) {
              byte[] temp = obuff;
              obuff = new byte[temp.length * 2];
              System.arraycopy(temp, 0, obuff, 0, temp.length);
            }
            System.arraycopy(ubuff, 0, obuff, total, nread);
            total += nread;
          }
          if (obuff.length >= 0) dout2.write(obuff, 0, total);
        } catch (BZip2ReadException ioe) {
          log.debug("Cinrad2IOSP.uncompress ", ioe);
        }
        float nrecords = (float) (total / 2432.0);
        if (debug)
          log.debug("  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + dout2.getFilePointer());
      }
      dout2.flush();
    } catch (EOFException e) {
      e.printStackTrace();
    } catch (Exception e) {
      dout2.close();
      throw e;
    }

    return dout2;
  }
private RandomAccessFile uncompress(RandomAccessFile raf2, String ufilename, boolean debug) throws IOException {
    raf2.seek(0);
    byte[] header = new byte[Cinrad2Record.FILE_HEADER_SIZE];
    int bytesRead = raf2.read(header);
    if (bytesRead != header.length) {
      throw new IOException("Error reading CINRAD header -- got " +
              bytesRead + " rather than" + header.length);
    }
    RandomAccessFile dout2 = new RandomAccessFile(ufilename, "rw");

    boolean eof = false;
    int numCompBytes;
    byte[] ubuff = new byte[40000];
    byte[] obuff = new byte[40000];
    try {
      dout2.write(header);
      CBZip2InputStream cbzip2 = new CBZip2InputStream();
      while (!eof) {

        try {
          numCompBytes = raf2.readInt();
          if (numCompBytes == -1) {
            if (debug) log.debug("  done: numCompBytes=-1 ");
            break;
          }
        } catch (EOFException ee) {
          if (debug) log.debug("  got EOFException ");
          break; // assume this is ok
        }

        if (debug) {
          log.debug("reading compressed bytes " + numCompBytes + " input starts at " + raf2.getFilePointer() + "; output starts at " + dout2.getFilePointer());
        }
        /*
        * For some stupid reason, the last block seems to
        * have the number of bytes negated.  So, we just
        * assume that any negative number (other than -1)
        * is the last block and go on our merry little way.
        */
        if (numCompBytes < 0) {
          if (debug) log.debug("last block?" + numCompBytes);
          numCompBytes = -numCompBytes;
          eof = true;
        }
        byte[] buf = new byte[numCompBytes];
        raf2.readFully(buf);
        ByteArrayInputStream bis = new ByteArrayInputStream(buf, 2, numCompBytes - 2);

        //CBZip2InputStream cbzip2 = new CBZip2InputStream(bis);
        cbzip2.setStream(bis);
        int total = 0;
        int nread;
        /*
        while ((nread = cbzip2.read(ubuff)) != -1) {
          dout2.write(ubuff, 0, nread);
          total += nread;
        }
        */
        try {
          while ((nread = cbzip2.read(ubuff)) != -1) {
            if (total + nread > obuff.length) {
              byte[] temp = obuff;
              obuff = new byte[temp.length * 2];
              System.arraycopy(temp, 0, obuff, 0, temp.length);
            }
            System.arraycopy(ubuff, 0, obuff, total, nread);
            total += nread;
          }
          if (obuff.length >= 0) dout2.write(obuff, 0, total);
        } catch (BZip2ReadException ioe) {
          log.debug("Cinrad2IOSP.uncompress ", ioe);
        }
        float nrecords = (float) (total / 2432.0);
        if (debug)
          log.debug("  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + dout2.getFilePointer());
      }
      dout2.flush();
    } catch (EOFException e) {
      e.printStackTrace();
    } catch (Exception e) {
      dout2.close();
      throw e;
    }

    return dout2;
  }
private RandomAccessFile uncompress ( RandomAccessFile raf2 , String ufilename , boolean debug ) throws IOException { raf2 . seek ( 0 ) ; byte [ ] header = new byte [ Cinrad2Record . FILE_HEADER_SIZE ] ; int bytesRead = raf2 . read ( header ) ; if ( bytesRead != header . length ) { throw new IOException ( "Error reading CINRAD header -- got " + bytesRead + " rather than" + header . length ) ; } RandomAccessFile dout2 = new RandomAccessFile ( ufilename , "rw" ) ; boolean eof = false ; int numCompBytes ; byte [ ] ubuff = new byte [ 40000 ] ; byte [ ] obuff = new byte [ 40000 ] ; try { dout2 . write ( header ) ; CBZip2InputStream cbzip2 = new CBZip2InputStream ( ) ; while ( ! eof ) { try { numCompBytes = raf2 . readInt ( ) ; if ( numCompBytes == - 1 ) { if ( debug ) log . debug ( "  done: numCompBytes=-1 " ) ; break ; } } catch ( EOFException ee ) { if ( debug ) log . debug ( "  got EOFException " ) ; break ; // assume this is ok } if ( debug ) { log . debug ( "reading compressed bytes " + numCompBytes + " input starts at " + raf2 . getFilePointer ( ) + "; output starts at " + dout2 . getFilePointer ( ) ) ; } /*
        * For some stupid reason, the last block seems to
        * have the number of bytes negated.  So, we just
        * assume that any negative number (other than -1)
        * is the last block and go on our merry little way.
        */ if ( numCompBytes < 0 ) { if ( debug ) log . debug ( "last block?" + numCompBytes ) ; numCompBytes = - numCompBytes ; eof = true ; } byte [ ] buf = new byte [ numCompBytes ] ; raf2 . readFully ( buf ) ; ByteArrayInputStream bis = new ByteArrayInputStream ( buf , 2 , numCompBytes - 2 ) ; //CBZip2InputStream cbzip2 = new CBZip2InputStream(bis); cbzip2 . setStream ( bis ) ; int total = 0 ; int nread ; /*
        while ((nread = cbzip2.read(ubuff)) != -1) {
          dout2.write(ubuff, 0, nread);
          total += nread;
        }
        */ try { while ( ( nread = cbzip2 . read ( ubuff ) ) != - 1 ) { if ( total + nread > obuff . length ) { byte [ ] temp = obuff ; obuff = new byte [ temp . length * 2 ] ; System . arraycopy ( temp , 0 , obuff , 0 , temp . length ) ; } System . arraycopy ( ubuff , 0 , obuff , total , nread ) ; total += nread ; } if ( obuff . length >= 0 ) dout2 . write ( obuff , 0 , total ) ; } catch ( BZip2ReadException ioe ) { log . debug ( "Cinrad2IOSP.uncompress " , ioe ) ; } float nrecords = ( float ) ( total / 2432.0 ) ; if ( debug ) log . debug ( "  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + dout2 . getFilePointer ( ) ) ; } dout2 . flush ( ) ; } catch ( EOFException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { dout2 . close ( ) ; throw e ; } return dout2 ; }
Write equivilent uncompressed version of the file.

@param raf2      file to uncompress
@param ufilename write to this file
@return raf of uncompressed file
@throws IOException
Write equivilent uncompressed version of the file .