cdm/src/main/java/ucar/nc2/iosp/nexrad2/Level2VolumeScan.java
private RandomAccessFile uncompress(RandomAccessFile inputRaf, String ufilename) throws IOException {
    RandomAccessFile outputRaf = new RandomAccessFile(ufilename, "rw");
    FileLock lock;

    while (true) { // loop waiting for the lock
      try {
        lock = outputRaf.getRandomAccessFile().getChannel().lock(0, 1, false);
        break;

      } catch (OverlappingFileLockException oe) { // not sure why lock() doesnt block
        try {
          Thread.sleep(100); // msecs
        } catch (InterruptedException e1) {
        }
      } catch (IOException e) {
          outputRaf.close();
          throw e;
      }
    }

    try {
        inputRaf.seek(0);
        byte[] header = new byte[Level2Record.FILE_HEADER_SIZE];
        int bytesRead = inputRaf.read(header);
        if (bytesRead != header.length)
        {
            throw new IOException("Error reading NEXRAD2 header -- got " +
                    bytesRead + " rather than" + header.length);
        }
        outputRaf.write(header);

        boolean eof = false;
        int numCompBytes;
        byte[] ubuff = new byte[40000];
        byte[] obuff = new byte[40000];

        CBZip2InputStream cbzip2 = new CBZip2InputStream();
        while (!eof) {
            try {
                numCompBytes = inputRaf.readInt();
                if (numCompBytes == -1) {
                    if (log.isDebugEnabled())
                        log.debug("  done: numCompBytes=-1 ");
                    break;
                }
            } catch (EOFException ee) {
                log.debug("got EOFException");
                break; // assume this is ok
            }

            if (log.isDebugEnabled()) {
                log.debug("reading compressed bytes " + numCompBytes + " input starts at " + inputRaf.getFilePointer() + "; output starts at " + outputRaf.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 (log.isDebugEnabled())
                    log.debug("last block?" + numCompBytes);
                numCompBytes = -numCompBytes;
                eof = true;
            }
            byte[] buf = new byte[numCompBytes];
            inputRaf.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) outputRaf.write(obuff, 0, total);
            } catch (BZip2ReadException ioe) {
                log.warn("Nexrad2IOSP.uncompress ", ioe);
            }
            float nrecords = (float) (total / 2432.0);
            if (log.isDebugEnabled())
                log.debug("  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + outputRaf.getFilePointer());
        }

        outputRaf.flush();
    } catch (IOException e) {
        if (outputRaf != null) outputRaf.close();

        // dont leave bad files around
        File ufile = new File(ufilename);
        if (ufile.exists()) {
            if (!ufile.delete())
                log.warn("failed to delete uncompressed file (IOException)" + ufilename);
        }

        throw e;
    } finally {
      try {
          if (lock != null) lock.release();
      } catch (IOException e) {
          if (outputRaf != null) outputRaf.close();
          throw e;
      }
    }

    return outputRaf;
  }
private RandomAccessFile uncompress(RandomAccessFile inputRaf, String ufilename) throws IOException {
    RandomAccessFile outputRaf = new RandomAccessFile(ufilename, "rw");
    FileLock lock;

    while (true) { // loop waiting for the lock
      try {
        lock = outputRaf.getRandomAccessFile().getChannel().lock(0, 1, false);
        break;

      } catch (OverlappingFileLockException oe) { // not sure why lock() doesnt block
        try {
          Thread.sleep(100); // msecs
        } catch (InterruptedException e1) {
        }
      } catch (IOException e) {
          outputRaf.close();
          throw e;
      }
    }

    try {
        inputRaf.seek(0);
        byte[] header = new byte[Level2Record.FILE_HEADER_SIZE];
        int bytesRead = inputRaf.read(header);
        if (bytesRead != header.length)
        {
            throw new IOException("Error reading NEXRAD2 header -- got " +
                    bytesRead + " rather than" + header.length);
        }
        outputRaf.write(header);

        boolean eof = false;
        int numCompBytes;
        byte[] ubuff = new byte[40000];
        byte[] obuff = new byte[40000];

        CBZip2InputStream cbzip2 = new CBZip2InputStream();
        while (!eof) {
            try {
                numCompBytes = inputRaf.readInt();
                if (numCompBytes == -1) {
                    if (log.isDebugEnabled())
                        log.debug("  done: numCompBytes=-1 ");
                    break;
                }
            } catch (EOFException ee) {
                log.debug("got EOFException");
                break; // assume this is ok
            }

            if (log.isDebugEnabled()) {
                log.debug("reading compressed bytes " + numCompBytes + " input starts at " + inputRaf.getFilePointer() + "; output starts at " + outputRaf.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 (log.isDebugEnabled())
                    log.debug("last block?" + numCompBytes);
                numCompBytes = -numCompBytes;
                eof = true;
            }
            byte[] buf = new byte[numCompBytes];
            inputRaf.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) outputRaf.write(obuff, 0, total);
            } catch (BZip2ReadException ioe) {
                log.warn("Nexrad2IOSP.uncompress ", ioe);
            }
            float nrecords = (float) (total / 2432.0);
            if (log.isDebugEnabled())
                log.debug("  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + outputRaf.getFilePointer());
        }

        outputRaf.flush();
    } catch (IOException e) {
        if (outputRaf != null) outputRaf.close();

        // dont leave bad files around
        File ufile = new File(ufilename);
        if (ufile.exists()) {
            if (!ufile.delete())
                log.warn("failed to delete uncompressed file (IOException)" + ufilename);
        }

        throw e;
    } finally {
      try {
          if (lock != null) lock.release();
      } catch (IOException e) {
          if (outputRaf != null) outputRaf.close();
          throw e;
      }
    }

    return outputRaf;
  }
private RandomAccessFile uncompress ( RandomAccessFile inputRaf , String ufilename ) throws IOException { RandomAccessFile outputRaf = new RandomAccessFile ( ufilename , "rw" ) ; FileLock lock ; while ( true ) { // loop waiting for the lock try { lock = outputRaf . getRandomAccessFile ( ) . getChannel ( ) . lock ( 0 , 1 , false ) ; break ; } catch ( OverlappingFileLockException oe ) { // not sure why lock() doesnt block try { Thread . sleep ( 100 ) ; // msecs } catch ( InterruptedException e1 ) { } } catch ( IOException e ) { outputRaf . close ( ) ; throw e ; } } try { inputRaf . seek ( 0 ) ; byte [ ] header = new byte [ Level2Record . FILE_HEADER_SIZE ] ; int bytesRead = inputRaf . read ( header ) ; if ( bytesRead != header . length ) { throw new IOException ( "Error reading NEXRAD2 header -- got " + bytesRead + " rather than" + header . length ) ; } outputRaf . write ( header ) ; boolean eof = false ; int numCompBytes ; byte [ ] ubuff = new byte [ 40000 ] ; byte [ ] obuff = new byte [ 40000 ] ; CBZip2InputStream cbzip2 = new CBZip2InputStream ( ) ; while ( ! eof ) { try { numCompBytes = inputRaf . readInt ( ) ; if ( numCompBytes == - 1 ) { if ( log . isDebugEnabled ( ) ) log . debug ( "  done: numCompBytes=-1 " ) ; break ; } } catch ( EOFException ee ) { log . debug ( "got EOFException" ) ; break ; // assume this is ok } if ( log . isDebugEnabled ( ) ) { log . debug ( "reading compressed bytes " + numCompBytes + " input starts at " + inputRaf . getFilePointer ( ) + "; output starts at " + outputRaf . 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 ( log . isDebugEnabled ( ) ) log . debug ( "last block?" + numCompBytes ) ; numCompBytes = - numCompBytes ; eof = true ; } byte [ ] buf = new byte [ numCompBytes ] ; inputRaf . 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 ) outputRaf . write ( obuff , 0 , total ) ; } catch ( BZip2ReadException ioe ) { log . warn ( "Nexrad2IOSP.uncompress " , ioe ) ; } float nrecords = ( float ) ( total / 2432.0 ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  unpacked " + total + " num bytes " + nrecords + " records; ouput ends at " + outputRaf . getFilePointer ( ) ) ; } outputRaf . flush ( ) ; } catch ( IOException e ) { if ( outputRaf != null ) outputRaf . close ( ) ; // dont leave bad files around File ufile = new File ( ufilename ) ; if ( ufile . exists ( ) ) { if ( ! ufile . delete ( ) ) log . warn ( "failed to delete uncompressed file (IOException)" + ufilename ) ; } throw e ; } finally { try { if ( lock != null ) lock . release ( ) ; } catch ( IOException e ) { if ( outputRaf != null ) outputRaf . close ( ) ; throw e ; } } return outputRaf ; }
Write equivilent uncompressed version of the file.

@param inputRaf  file to uncompress
@param ufilename write to this file
@return raf of uncompressed file
@throws IOException on read error
Write equivilent uncompressed version of the file .