Ejemplo n.º 1
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
Ejemplo n.º 2
0
 public void setObjectValues() {
   ((JTextField) (fields.get("board"))).setText(sketch.getBoard().getName());
   ((JTextField) (fields.get("core"))).setText(sketch.getCore().getName());
   ((JTextField) (fields.get("compiler"))).setText(sketch.getCompiler().getName());
   ((JTextField) (fields.get("port"))).setText(sketch.getDevice().toString());
   ((JTextField) (fields.get("programmer"))).setText(sketch.getProgrammer());
 }
Ejemplo n.º 3
0
    public String hasSameContent(JarFile2 file, JarEntry entry) throws IOException {

      String thisName = null;

      Long crcL = new Long(entry.getCrc());

      // check if this jar contains files with the passed in entry's crc
      if (_crcToEntryMap.containsKey(crcL)) {
        // get the Linked List with files with the crc
        LinkedList ll = (LinkedList) _crcToEntryMap.get(crcL);
        // go through the list and check for content match
        ListIterator li = ll.listIterator(0);
        if (li != null) {
          while (li.hasNext()) {
            JarEntry thisEntry = (JarEntry) li.next();

            // check for content match
            InputStream oldIS = getJarFile().getInputStream(thisEntry);
            InputStream newIS = file.getJarFile().getInputStream(entry);

            if (!differs(oldIS, newIS)) {
              thisName = thisEntry.getName();
              return thisName;
            }
          }
        }
      }

      return thisName;
    }
 public ArrayList getPointList(long handId) {
   ArrayList curList;
   if (_pointLists.containsKey(handId)) curList = (ArrayList) _pointLists.get(handId);
   else {
     curList = new ArrayList(_maxPoints);
     _pointLists.put(handId, curList);
   }
   return curList;
 }
Ejemplo n.º 5
0
  public boolean readDocument() {
    try {
      myStream = new ZLInputStreamWithOffset(myFile.getInputStream());

      PdbHeader header = new PdbHeader(myStream);

      setMainTextModel();
      myFont = FontType.FT_REGULAR;

      for (int index = 0; index < header.Offsets.length; ++index) {
        int currentOffset = myStream.offset();
        int pit = header.Offsets[index];
        if (currentOffset > pit) {
          break;
        }
        // myStream.seek(pit - currentOffset, false);
        myStream.skip(pit - currentOffset);

        if (myStream.offset() != pit) {
          break;
        }
        int recordSize =
            ((index != header.Offsets.length - 1) ? header.Offsets[index + 1] : myFileSize) - pit;
        readRecord(recordSize);
      }
      myStream.close();
    } catch (IOException e) {
      return false;
    }

    for (Iterator it = myReferencedParagraphs.iterator(); it.hasNext(); ) {
      Pair pair = (Pair) it.next();
      int first = (Integer) pair.myFirst;
      int second = (Integer) pair.mySecond;
      ArrayList /*<Integer>*/ list = (ArrayList) myParagraphMap.get(first);
      if (list != null) {
        for (int k = second; k < list.size(); ++k) {
          if (((Integer) ((Pair) list.get(k)).myFirst) != -1) {
            // addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second),
            // (Integer)list.get(k));
            final Pair p = (Pair) list.get(k);
            // addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer) p.mySecond,
            // (Integer) p.myFirst);
            break;
          }
        }
      }
    }
    myReferencedParagraphs.clear();
    myParagraphMap.clear();
    return true;
  }
Ejemplo n.º 6
0
    private void index() throws IOException {
      Enumeration entries = _jar.entries();

      _nameToEntryMap = new HashMap();
      _crcToEntryMap = new HashMap();

      _entries = new ArrayList();
      if (_debug) {
        System.out.println("indexing: " + _jar.getName());
      }
      if (entries != null) {
        while (entries.hasMoreElements()) {
          JarEntry entry = (JarEntry) entries.nextElement();

          long crc = entry.getCrc();

          Long crcL = new Long(crc);

          if (_debug) {
            System.out.println("\t" + entry.getName() + " CRC " + crc);
          }

          _nameToEntryMap.put(entry.getName(), entry);
          _entries.add(entry);

          // generate the CRC to entries map
          if (_crcToEntryMap.containsKey(crcL)) {
            // key exist, add the entry to the correcponding
            // linked list

            // get the linked list
            LinkedList ll = (LinkedList) _crcToEntryMap.get(crcL);

            // put in the new entry
            ll.add(entry);

            // put it back in the hash map
            _crcToEntryMap.put(crcL, ll);
          } else {
            // create a new entry in the hashmap for the new key

            // first create the linked list and put in the new
            // entry
            LinkedList ll = new LinkedList();
            ll.add(entry);

            // create the new entry in the hashmap
            _crcToEntryMap.put(crcL, ll);
          }
        }
      }
    }
Ejemplo n.º 7
0
 /** @apilevel internal */
 private HashMap methodsSignatureMap_compute() {
   HashMap map = new HashMap(localMethodsSignatureMap());
   for (Iterator outerIter = superinterfacesIterator(); outerIter.hasNext(); ) {
     TypeDecl typeDecl = (TypeDecl) outerIter.next();
     for (Iterator iter = typeDecl.methodsIterator(); iter.hasNext(); ) {
       MethodDecl m = (MethodDecl) iter.next();
       if (!m.isPrivate()
           && m.accessibleFrom(this)
           && !localMethodsSignatureMap().containsKey(m.signature()))
         putSimpleSetElement(map, m.signature(), m);
     }
   }
   for (Iterator iter = typeObject().methodsIterator(); iter.hasNext(); ) {
     MethodDecl m = (MethodDecl) iter.next();
     if (m.isPublic() && !map.containsKey(m.signature()))
       putSimpleSetElement(map, m.signature(), m);
   }
   return map;
 }
    public void draw() {
      if (_pointLists.size() <= 0) return;

      pushStyle();
      noFill();

      PVector vec;
      PVector firstVec;
      PVector screenPos = new PVector();
      int colorIndex = 0;

      // draw the hand lists
      Iterator<Map.Entry> itrList = _pointLists.entrySet().iterator();
      while (itrList.hasNext()) {
        strokeWeight(2);
        stroke(_colorList[colorIndex % (_colorList.length - 1)]);

        ArrayList curList = (ArrayList) itrList.next().getValue();

        // draw line
        firstVec = null;
        Iterator<PVector> itr = curList.iterator();
        beginShape();
        while (itr.hasNext()) {
          vec = itr.next();
          if (firstVec == null) firstVec = vec;
          // calc the screen pos
          context.convertRealWorldToProjective(vec, screenPos);
          vertex(screenPos.x, screenPos.y);
        }
        endShape();

        // draw current pos of the hand
        if (firstVec != null) {
          strokeWeight(8);
          context.convertRealWorldToProjective(firstVec, screenPos);
          point(screenPos.x, screenPos.y);
        }
        colorIndex++;
      }

      popStyle();
    }
Ejemplo n.º 9
0
 void addTextField(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextField field = new JTextField();
   field.setText(sketch.configFile.get(key));
   field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height));
   fields.put(key, field);
   panel.add(field);
 }
Ejemplo n.º 10
0
  // this method basically will chop up the blocks and get their frequencies
  private static void getBlockFrequency() throws Exception {
    directory = "../../thesis-datasets/morph_file_100MB/";
    ReadFile.readFile(directory, fileList); // read the two files
    HashMap<Integer, Integer> blockFreq =
        new HashMap<Integer, Integer>(); // this stores the block in the map along there frequencies
    int start = 0; // start of the sliding window
    int end = start + window - 1; // ending boundary
    preliminaryStep(directory);
    // System.out.println("Choping the document TDDD " + fileList.get(0));
    long[] divisorArray = {
      1000
    }; // run the frequency code for these divisor values (AKA expected block Size)
    for (long i : divisorArray) {

      long divisor1 = i;
      long divisor2 = i / 2;
      long divisor3 = i / 4;
      long remainder = 7;
      long minBoundary = min_multiplier * i;
      long maxBoundary = max_multiplier * i;
      // System.out.println("Running Likelihood for " + i + " " + divisor2 + " " + divisor3);
      int totalBlocks =
          chopDocument(
              fileArray.get(0),
              hashed_File_List.get(0),
              divisor1,
              divisor2,
              divisor3,
              remainder,
              minBoundary,
              maxBoundary,
              blockFreq);
      // now output the block sizes, along with there frequencies and probilities
      for (Map.Entry<Integer, Integer> tuple : blockFreq.entrySet()) {
        // output the block freq
        double prob = (double) tuple.getValue() / (double) totalBlocks;
        System.out.println(tuple.getKey() + " " + tuple.getValue() + " " + prob);
      }

      blockFreq.clear();
    }
  }
Ejemplo n.º 11
0
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
Ejemplo n.º 12
0
 public void init(FilterConfig filterConfig) {
   this.config = filterConfig;
   this.encoding = config.getInitParameter("encoding");
   if (encoding == null || encoding.length() == 0) {
     encoding = "GBK";
   }
   expiresMap = new HashMap();
   Enumeration names = config.getInitParameterNames();
   while (names.hasMoreElements()) {
     String paramName = (String) names.nextElement();
     if (!"encoding".equals(paramName)) {
       String paramValue = config.getInitParameter(paramName);
       try {
         Integer expires = Integer.valueOf(config.getInitParameter(paramName));
         expiresMap.put(paramName, expires);
       } catch (Exception ex) {
         // LogUtil.logError( "Filter."+paramValue+"="+paramValue);
       }
     }
   }
 }
Ejemplo n.º 13
0
 private void setResponseHeader(
     HttpServletResponse response, String uri, String transferEncoding) {
   // LogUtil.logDebug( uri + ".Accept-Encoding: "+ transferEncoding);
   String ext = null;
   int dot = uri.lastIndexOf(".");
   if (dot != -1) {
     ext = uri.substring(dot + 1);
   }
   if (ext != null && ext.length() > 0) {
     Integer expires = (Integer) expiresMap.get(ext);
     if (expires != null) {
       // LogUtil.logDebug( uri + ".Expires: "+ expires.intValue());
       if (expires.intValue() > 0) {
         response.setHeader("Cache-Control", "max-age=" + expires.intValue()); // HTTP 1.1
       } else {
         response.setHeader("Cache-Control", "no-cache");
         response.setHeader("Pragma", "no-cache"); // HTTP 1.0
         response.setDateHeader("Expires", expires.intValue());
       }
     }
   }
 }
Ejemplo n.º 14
0
 public JarEntry getEntryByName(String name) {
   return (JarEntry) _nameToEntryMap.get(name);
 }
  /** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }
    public void OnPointDestroy(long nID) {
      println("OnPointDestroy, handId: " + nID);

      // remove list
      if (_pointLists.containsKey(nID)) _pointLists.remove(nID);
    }
Ejemplo n.º 17
0
  private void readRecord(int recordSize) throws IOException {
    int uid = PdbUtil.readShort(myStream);
    if (uid == 1) {
      myCompressionVersion = (short) PdbUtil.readShort(myStream);
    } else {
      int paragraphs = PdbUtil.readShort(myStream);

      int size = PdbUtil.readShort(myStream);
      // TODO ??????
      int type = myStream.read();

      int flags = myStream.read();

      switch (type) {
        case 0: // text (TODO: found sample file and test this code)
        case 1: // compressed text
          {
            ArrayList /*<Integer>*/ pars = new ArrayList();
            for (int i = 0; i < paragraphs; ++i) {
              int pSize = PdbUtil.readShort(myStream);
              pars.add(pSize);
              myStream.skip(2);
            }

            boolean doProcess = false;
            if (type == 0) { // ?
              byte[] buf = new byte[size];
              doProcess = myStream.read(buf, 0, (int) size) == size;
              if (doProcess) {
                // TODO: use encoding!!!!
                // TODO: don't create any new objects!!!!
                myCharBuffer = new String(buf).toCharArray();
              }
            } else if (myCompressionVersion == 1) {
              byte[] buf = new byte[size];
              doProcess =
                  DocDecompressor.decompress(myStream, buf, recordSize - 8 - 4 * paragraphs)
                      == size;
              if (doProcess) {
                myCharBuffer = new String(buf).toCharArray();
              }
            } else if (myCompressionVersion == 2) {
              byte input[] = new byte[(int) (recordSize - 10 - 4 * paragraphs)];
              final int inputSize = myStream.read(input);
              Inflater decompressor = new Inflater();
              decompressor.setInput(input, 0, inputSize);
              byte output[] = new byte[size];
              try {
                doProcess = decompressor.inflate(output) == size;
                decompressor.end();
                myCharBuffer = new String(output, 0, size).toCharArray();
              } catch (DataFormatException e) {
                // TODO Auto-generated catch block
                //	e.printStackTrace();
                System.out.println(e.getMessage());
              }
              // doProcess =
              // ZLZDecompressor(recordSize - 10 - 4 * paragraphs).
              // decompress(myStream, myCharBuffer, size) == size;
            }
            if (doProcess) {
              addHyperlinkLabel(fromNumber(uid));
              myParagraphMap.put(uid, new ArrayList());
              myParagraphVector = (ArrayList) myParagraphMap.get(uid);
              processTextRecord(size, pars);
              if ((flags & 0x1) == 0) {
                //							insertEndOfTextParagraph();
                // setNewTextModel();
              }
            }
            break;
          }
        case 2: // image
        case 3: // compressed image
          {
            final String mime = "image/palm";
            ZLImage image = null;
            if (type == 2) {
              System.out.println("non-compressed image");
              image = new PluckerFileImage(mime, myFile, myStream.offset(), recordSize - 8);
            } else if (myCompressionVersion == 1) {
              System.out.println("DocCompressedImage");
              image = new DocCompressedFileImage(mime, myFile, myStream.offset(), recordSize - 8);
            } else if (myCompressionVersion == 2) {
              System.out.println("ZCompressedImage");
              image =
                  new ZCompressedFileImage(mime, myFile, myStream.offset() + 2, recordSize - 10);
            }
            if (image != null) {
              addImage(fromNumber(uid), image);
            }
            break;
          }
        case 9: // category record is ignored
          break;
        case 10:
          short typeCode = (short) PdbUtil.readShort(myStream);
          break;
        case 11: // style sheet record is ignored
          break;
        case 12: // font page record is ignored
          break;
        case 13: // TODO: process tables
        case 14: // TODO: process tables
          break;
        case 15: // multiimage
          {
            short columns = (short) PdbUtil.readShort(myStream);
            short rows = (short) PdbUtil.readShort(myStream);
            System.out.println("multiimage");
            /*PluckerMultiImage image = new PluckerMultiImage(rows, columns, Model.getImageMap());
            for (int i = 0; i < size / 2 - 2; ++i) {
            	short us = (short)myStream.read();
            	PdbUtil.readShort(myStream, us);
            	image.addId(fromNumber(us));
            }
            addImage(fromNumber(uid), image);
            */ break;
          }
        default:
          // std::cerr << "type = " << (int)type << "\n";
          break;
      }
    }
  }
Ejemplo n.º 18
0
  /* -------------------------------------------------------------------------------------------------------
  This method:
  	--	Takes in three paramters:
  		1. array - this is the byte array that actually holds the document contents
  		2. md5Hases - holds the entire hash values of the document
  		3. Divisor1/Divisor2 - main and back up divisor
  		5. The remainder we are looking for
  		6/7. min/max boundaries
  		8. blockFreq - store the block sizes and how many time's they occur

  	-- We are simply choping up the first file
  -------------------------------------------------------------------------------------------------------- */
  private static int chopDocument(
      byte[] array,
      ArrayList<Long> md5Hashes,
      long divisor1,
      long divisor2,
      long divisor3,
      long remainder,
      long minBoundary,
      long maxBoundary,
      HashMap<Integer, Integer> blockFreq) {

    int documentStart = 0; // used to keep track of where the boundaries are
    boolean match = false; // used to ck if we encountered a match
    int backUpBreakPoint = -1; // used to store the backup breakpoint
    int secondBackUpBreakPoint = -1; // this is the second backup point with the divisor3
    StringBuilder builder = new StringBuilder();
    int counter = 0;
    int i = documentStart + (int) minBoundary - 1; // so we start at the minimum
    // loop through all the values in the document
    for (; i < md5Hashes.size(); ++i) {

      if (md5Hashes.get(i) % divisor1 == remainder) // ck if this equals the mod value
      {
        int size = i - documentStart + 1; // we only care about the size
        if (blockFreq.get(size) == null) // if not in there, then simply store it
        blockFreq.put(size, 1);
        else // increment it's integer count
        blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
        counter++; // increment the block count
        documentStart = i + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1; // second backup point reset it!
        i = i + (int) minBoundary - 1; // skip all the way here
      } else if (md5Hashes.get(i) % divisor2 == remainder) { //  check if this is the backup point
        backUpBreakPoint = i; // this is the backup breakpoint
      } else if (md5Hashes.get(i) % divisor3 == remainder) {
        secondBackUpBreakPoint = i; // we found a second backup point with divisor3
      }
      if ((i - documentStart + 1) >= maxBoundary) { // we have reached the maximum
        // ck if we have a backUpbreakpoint
        int point;
        if (backUpBreakPoint != -1) // if we do, set this as the boundary
        point = backUpBreakPoint;
        else if (secondBackUpBreakPoint != -1)
          point = secondBackUpBreakPoint; // if we don't have a first backup, ck if we have a second
        else point = i; // else this current value of i is the breakpoint

        // Hash all the values in the range (documentStart,point
        // Remember we only want to hash the original VALUES from the array that contains the
        // original
        // content of the file. Not the hash values in the md5Hash Array
        int size = point - documentStart + 1; // we only care about the size
        if (blockFreq.get(size) == null) // if not in there, then simply store it
        blockFreq.put(size, 1);
        else // increment it's integer count
        blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
        counter++; // increment the block count
        documentStart = point + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1; // reset second backup break point
        i = point + (int) minBoundary - 1; // so we start at the minimum
      }
    } // end of the for loop

    // -------------------------------------------------------------------------------------------
    //  we are missing the last boundary, so hash that last value
    //	We will also check against our values of the strings we already have, and if we encountered
    // this
    //	already, then we will simply increment the counter, otherwise we will insert it in the
    // hashtable
    //	and increase our miss counter
    // ----------------------------------------------------------------------------------------------
    int size = array.length - documentStart; // we start from the point
    if (blockFreq.get(size) == null) // if not in there, then simply store it
    blockFreq.put(size, 1);
    else // increment it's integer count
    blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
    return ++counter; // increment the block count
  } // end of the method
Ejemplo n.º 19
0
  /** Creates a patch from the two passed in files, writing the result to <code>os</code>. */
  public static void createPatch(String oldPath, String newPath, OutputStream os, boolean minimal)
      throws IOException {
    JarFile2 oldJar = new JarFile2(oldPath);
    JarFile2 newJar = new JarFile2(newPath);

    try {
      Iterator entries;
      HashMap moved = new HashMap();
      HashSet visited = new HashSet();
      HashSet implicit = new HashSet();
      HashSet moveSrc = new HashSet();
      HashSet newEntries = new HashSet();

      // FIRST PASS
      // Go through the entries in new jar and
      // determine which files are candidates for implicit moves
      // ( files that has the same filename and same content in old.jar
      // and new.jar )
      // and for files that cannot be implicitly moved, we will either
      // find out whether it is moved or new (modified)
      entries = newJar.getJarEntries();
      if (entries != null) {
        while (entries.hasNext()) {
          JarEntry newEntry = (JarEntry) entries.next();
          String newname = newEntry.getName();

          // Return best match of contents, will return a name match if possible
          String oldname = oldJar.getBestMatch(newJar, newEntry);
          if (oldname == null) {
            // New or modified entry
            if (_debug) {
              System.out.println("NEW: " + newname);
            }
            newEntries.add(newname);
          } else {
            // Content already exist - need to do a move

            // Should do implicit move? Yes, if names are the same, and
            // no move command already exist from oldJar
            if (oldname.equals(newname) && !moveSrc.contains(oldname)) {
              if (_debug) {
                System.out.println(newname + " added to implicit set!");
              }
              implicit.add(newname);
            } else {
              // The 1.0.1/1.0 JarDiffPatcher cannot handle
              // multiple MOVE command with same src.
              // The work around here is if we are going to generate
              // a MOVE command with duplicate src, we will
              // instead add the target as a new file.  This way
              // the jardiff can be applied by 1.0.1/1.0
              // JarDiffPatcher also.
              if (!minimal && (implicit.contains(oldname) || moveSrc.contains(oldname))) {

                // generate non-minimal jardiff
                // for backward compatibility

                if (_debug) {

                  System.out.println("NEW: " + newname);
                }
                newEntries.add(newname);
              } else {
                // Use newname as key, since they are unique
                if (_debug) {
                  System.err.println("moved.put " + newname + " " + oldname);
                }
                moved.put(newname, oldname);
                moveSrc.add(oldname);
              }
              // Check if this disables an implicit 'move <oldname> <oldname>'
              if (implicit.contains(oldname) && minimal) {

                if (_debug) {
                  System.err.println("implicit.remove " + oldname);

                  System.err.println("moved.put " + oldname + " " + oldname);
                }
                implicit.remove(oldname);
                moved.put(oldname, oldname);
                moveSrc.add(oldname);
              }
            }
          }
        }
      } // if (entries != null)

      // SECOND PASS: <deleted files> = <oldjarnames> - <implicitmoves> -
      // <source of move commands> - <new or modified entries>
      ArrayList deleted = new ArrayList();
      entries = oldJar.getJarEntries();
      if (entries != null) {
        while (entries.hasNext()) {
          JarEntry oldEntry = (JarEntry) entries.next();
          String oldName = oldEntry.getName();
          if (!implicit.contains(oldName)
              && !moveSrc.contains(oldName)
              && !newEntries.contains(oldName)) {
            if (_debug) {
              System.err.println("deleted.add " + oldName);
            }
            deleted.add(oldName);
          }
        }
      }

      // DEBUG
      if (_debug) {
        // DEBUG:  print out moved map
        entries = moved.keySet().iterator();
        if (entries != null) {
          System.out.println("MOVED MAP!!!");
          while (entries.hasNext()) {
            String newName = (String) entries.next();
            String oldName = (String) moved.get(newName);
            System.out.println("key is " + newName + " value is " + oldName);
          }
        }

        // DEBUG:  print out IMOVE map
        entries = implicit.iterator();
        if (entries != null) {
          System.out.println("IMOVE MAP!!!");
          while (entries.hasNext()) {
            String newName = (String) entries.next();
            System.out.println("key is " + newName);
          }
        }
      }

      JarOutputStream jos = new JarOutputStream(os);

      // Write out all the MOVEs and REMOVEs
      createIndex(jos, deleted, moved);

      // Put in New and Modified entries
      entries = newEntries.iterator();
      if (entries != null) {

        while (entries.hasNext()) {
          String newName = (String) entries.next();
          if (_debug) {
            System.out.println("New File: " + newName);
          }
          writeEntry(jos, newJar.getEntryByName(newName), newJar);
        }
      }

      jos.finish();
      jos.close();

    } catch (IOException ioE) {
      throw ioE;
    } finally {
      try {
        oldJar.getJarFile().close();
      } catch (IOException e1) {
        // ignore
      }
      try {
        newJar.getJarFile().close();
      } catch (IOException e1) {
        // ignore
      }
    } // finally
  }
Ejemplo n.º 20
0
 public static String getInfo(String item) {
   return pluginInfo.get(item);
 }