Logo Search packages:      
Sourcecode: jlha-utils version File versions  Download package

void org::jlhafrontend::JLHAFrontEnd::createFile ( Opts  useropts,
LhaOutputStream  lio,
String  filename 
) [inline]

compress a file into a LhaOutputStream

Parameters:
useropts Options input by users
lio the LhaOutputStream for an archive file
filename the file need to be compressed

Definition at line 1362 of file JLHAFrontEnd.java.

References calEntropy(), org::jlhafrontend::Opts::getCompressionMethod(), org::jlhafrontend::Opts::getDeleteFiles(), org::jlhafrontend::Opts::getEUCMode(), org::jlhafrontend::Opts::getFileNotCompress(), org::jlhafrontend::Opts::getQuiet(), org::jlhafrontend::Opts::getTextMode(), mylogger, org::jlhafrontend::ListFormatter::toField(), and transferTo().

Referenced by createSwitcher().

                                                                                {
      LhaHeader header = new LhaHeader( filename );
      FileInputStream raf = null;
      File fl;
      int i,j,quiet=0;
      boolean fileNotCompress=false,deleteFiles=false;
      ListFormatter lf = new ListFormatter();
      int compressMethod=0;
      long compressedSize=0;
      long[] distributiontable=new long[256];
      OutputStream liodata;

      compressMethod = useropts.getCompressionMethod();
      fileNotCompress = useropts.getFileNotCompress();
      deleteFiles = useropts.getDeleteFiles();
      quiet = useropts.getQuiet();
      try {
          fl = new File(filename);
      } catch (Exception e) {
          mylogger.severe("new File error: "+e.toString());
          return;
      }

      try {
          raf = new FileInputStream( fl );
      } catch (Exception e) {
          mylogger.severe("new FileInputStream: "+e.toString());
          return;
      }

      header.setLastModified( new Date( fl.lastModified() ) );
      header.setOriginalSize( fl.length());
      header.setOSID((byte)0);
      if (compressMethod == 5) {
          header.setCompressMethod ( CompressMethod.LH5 );
      } else if (compressMethod == 6) {
          header.setCompressMethod ( CompressMethod.LH6 );
      } else if (compressMethod == 7) {
          header.setCompressMethod ( CompressMethod.LH7 );
      }
      if (fileNotCompress) {
          header.setCompressMethod ( CompressMethod.LH0 );
      }
      try {
          lio.putNextEntry( header );
      } catch (IOException e) {
          mylogger.severe("putNextEntry error #1: "+e.toString());
      }
      if (quiet==0) {
          System.out.print(filename);
          System.out.print("\t- Frozen");
          System.out.flush();
      }
      liodata = lio;
      if (useropts.getTextMode()) {
          liodata = new Unix2DOSOutputStream(liodata);
      }
      if (useropts.getEUCMode()) {
          liodata = new EUCJP2SJISOutputStream(liodata);
      }
      j=transferTo(raf,liodata,distributiontable);
      try {
          lio.closeEntry();
      } catch (IOException e) {
          mylogger.severe("lio.closeEntry #1: "+e.toString());
      }
      if (quiet==0) {
          //compressedSize = header.getCompressedSize();
          compressedSize = calEntropy(distributiontable); /* FIXME: display correct compression rate */
          if (header.getOriginalSize() > 0 && header.getOriginalSize() > compressedSize) {
            System.out.print(lf.toField("("+Long.toString(compressedSize*100/header.getOriginalSize())+"%)",6,true));
            } else {
                System.out.print(lf.toField("(100%)",6,true));
            }
                    
          for (i=0 ; i<j && i<80-(filename.length()/8+1)*8-14-1 ; i++) {
            System.out.print("o");
                System.out.flush();
          }
      }
      if (deleteFiles) {
          try {
            fl.delete();
          } catch (Exception e) {
            mylogger.warning("cannot delete files"+fl.getAbsolutePath()+" : "+e.toString());
          }
      }
      if (quiet==0) {
          System.out.println("");
      }
    }


Generated by  Doxygen 1.6.0   Back to index