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

void org::jlhafrontend::JLHAFrontEnd::print ( Opts  useropts,
String  archiveFilename,
String[]  filesFilename 
) [inline]

execute print to stdout command

Parameters:
useropts Options input by users
archiveFilename the filename of the archive file
filesFilename the array of filenames to be processed

Definition at line 1042 of file JLHAFrontEnd.java.

References org::jlhafrontend::Opts::getIgnorePath(), org::jlhafrontend::Opts::getVerbose(), isInArray(), and mylogger.

Referenced by start().

                                                                                     {
      LhaFile archiveFile=null;
      LhaHeader[] lhaEntries=null;
      int i,j,k=0;
      InputStream compressedInputStream=null;
      boolean ignorePath=false,verbose=false;
      File uncompressedFile;
      String filename;
      byte[] buf = new byte[1024*8];
      int bufRead=0;

      try {
          archiveFile = new LhaFile (new File(archiveFilename));
      } catch (FileNotFoundException e) {
          System.err.println("LHa: Fatal error: "+archiveFilename+": No such file or directory");
          return;
      } catch (Exception e) {
          mylogger.warning("Open "+archiveFilename+" error:"+e.toString());             System.err.println("LHa: Warning: Checksum error (LHarc file?)");
          System.err.println("LHa: Fatal error: Unkonwn header (lha file?)");
          return;
      }
      
      ignorePath = useropts.getIgnorePath();
      verbose = useropts.getVerbose();

      lhaEntries = archiveFile.getEntries();

      for (i=0 ; i<lhaEntries.length; i++) {
          filename = lhaEntries[i].getPath();
          if (filesFilename != null && !isInArray(filename,filesFilename)) {
            continue;
          }
          uncompressedFile = new File(filename);
          /* extract path */
          if (lhaEntries[i].getCompressMethod().compareTo(CompressMethod.LHD)==0) {
            continue;
          }
          if (ignorePath) {
            uncompressedFile = new File(uncompressedFile.getName());
          }
          System.out.println("::::::::");
          if (ignorePath) {
            System.out.print(uncompressedFile.getName());
            k = uncompressedFile.getName().length();
          } else {
            System.out.print(filename);
            k = filename.length();
          }
          System.out.println("");
          System.out.println("::::::::");
          compressedInputStream = archiveFile.getInputStream(lhaEntries[i]);

          for (j=0; true; j++) {
            try {
                bufRead=compressedInputStream.read(buf);
            } catch (Exception e) {
                mylogger.severe("read from compressedInputStream "+e.toString());
                break;
            }
            if (bufRead<=0) break;
            try {
                System.out.write(buf,0,bufRead);
            } catch (Exception e) {
                mylogger.severe("write to uncompressedOutputStream "+e.toString());
                break;
            }
          }

          try {
            compressedInputStream.close();
          } catch (IOException e) {
            mylogger.severe("closing compressedInputStream "+e.toString());
          }
      }

      try {
          archiveFile.close();
      } catch (IOException e) {
          mylogger.warning("Close "+archiveFilename+" error:"+e.toString());
      }
      
    }


Generated by  Doxygen 1.6.0   Back to index