Пример #1
0
    private void join(File aFile) throws Exception {

      Properties theProperties = myProperties;
      String theLocalBaseDir = theProperties.getProperty("LOCALBASEDIR");

      try {

        myMessage.stateChanged("JOIN");
        myMessage.messageChanged(0, "In join");
        myMessage.messageChanged(0, "My file name is " + aFile.getName());
        myMessage.messageChanged(0, "My file full path  is " + aFile.getPath());
        // myMessage.messageChanged(0, "My MD5 value is "+MD5.getMD5(aFile));
        /**
         * myMessage.messageChanged(0, "Delete files from "+theLocalTempDir);
         *
         * <p>File directory = new File(theLocalTempDir); // Get all files in directory File[] files
         * = directory.listFiles(); for (File file : files) { // Delete each file if
         * (!file.delete()) { // Failed to delete file System.out.println("Failed to delete "+file);
         * } }*
         */
        myMessage.messageChanged(0, "Joining files into " + theLocalBaseDir);
        File theBaseDir = new File(theLocalBaseDir);
        Joiner theJoiner = new Joiner(aFile.getAbsolutePath(), theLocalBaseDir);
        /**
         * int theFileSplitSize = Integer.parseInt(theProperties.getProperty("LOCALFILESPLITSIZE"));
         * int theFileSplitBufferSize =
         * Integer.parseInt(theProperties.getProperty("LOCALFILESPLITBUFSIZE")); long
         * theNumIterations = (long)Math.ceil((float)aFile.length()/(float)theFileSplitSize); long
         * theCurrentIteration = 0; Splitter theSplitter = new
         * Splitter(aFile.getPath(),theLocalTempDir,theFileSplitSize,theFileSplitBufferSize);
         * myMessage.messageChanged(0, "Splitting FileName"+theSplitter.getNextTargetName());*
         */
        long theNumIterations = theJoiner.getNumSplitFiles();
        long theCurrentIteration = 0;
        while (theJoiner.moreToJoin() && !isCancelled()) {
          theJoiner.go();
          theCurrentIteration++;
          if (theJoiner.moreToJoin()) {
            myMessage.messageChanged(
                (int) getPercentage(theCurrentIteration, theNumIterations),
                "Joining FileName" + theJoiner.getNextSourceName());
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      if (!isCancelled()) {
        myMessage.messageChanged(100, "done");
      } else {
        myMessage.messageChanged("Canceled in split");
      }
    }