Пример #1
0
  public void writeStream(DataInputStream input) throws IOException, NoSuchAlgorithmException {
    try {
      int bytesRead = 0;
      int bytesToSkip = 0;

      while (true) {
        final int value = input.readUnsignedByte();
        bytesRead++;
        check.nextByte(value);
        writeRaw(value);
        final int weakChecksum = check.weakChecksum();
        String strongChecksum = null;

        if (bytesToSkip > 0) {
          bytesToSkip--;
        } else {
          Map<String, Integer> weakMatches = inputBlocks.get(weakChecksum);
          if (weakMatches != null) {
            strongChecksum = check.strongChecksum();
            Integer previousOffset = weakMatches.get(strongChecksum);
            if (previousOffset != null) {
              snipRawBuffer();
              System.err.println(
                  "Using previously remembered : "
                      + previousOffset
                      + " : "
                      + (bytesRead - BLOCK_SIZE));
              writeBlock(previousOffset);
              bytesToSkip = BLOCK_SIZE - 1;
            }
          }
        }

        if ((bytesRead % BLOCK_SIZE) == 0) {
          Map<String, Integer> weakMatches = inputBlocks.get(weakChecksum);
          if (weakMatches == null) {
            weakMatches = new HashMap<String, Integer>();
            inputBlocks.put(weakChecksum, weakMatches);
          }
          if (strongChecksum == null) {
            strongChecksum = check.strongChecksum();
          }
          if (!weakMatches.containsKey(strongChecksum)) {
            weakMatches.put(strongChecksum, bytesRead - BLOCK_SIZE);
            System.err.println(
                "Remembering : "
                    + weakChecksum
                    + " : "
                    + strongChecksum
                    + " : "
                    + (bytesRead - BLOCK_SIZE));
          }
        }
      }
    } catch (EOFException e) {
      flushRaw();
    }
    System.err.println("Original data: " + rawChunks);
    System.err.println("Reused data: " + blockChunks);
  }
Пример #2
0
  /**
   * Create page token if it doesn't exist.
   *
   * @param pageTokens A map of tokens. If token doesn't exist it will be added.
   * @param uri The key for the tokens.
   */
  private void createPageToken(Map<String, String> pageTokens, String uri) {

    if (pageTokens == null) return;

    /** create token if it does not exist * */
    if (pageTokens.containsKey(uri)) return;
    try {
      pageTokens.put(uri, RandomGenerator.generateRandomId(getPrng(), getTokenLength()));
    } catch (Exception e) {
      throw new RuntimeException(
          String.format("unable to generate the random token - %s", e.getLocalizedMessage()), e);
    }
  }
Пример #3
0
  /**
   * The entry point into the Parser class.
   *
   * @param root A RootDoc intstance obtained via the doclet API
   * @return A XML (XStream) serializable element, containing everything parsed from javadoc doclet
   */
  public static Root ParseRoot(RootDoc root) {
    processingStorage = new HashMap<PackageDoc, ParserMediary>();

    try {
      md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      log.error("unable to acquire MD5 algorithm", e);
      return null;
    }

    rootXml = new Root();

    ClassDoc[] allClasses = root.classes();

    for (ClassDoc classDoc : allClasses) {
      PackageDoc doc = classDoc.containingPackage();

      ParserMediary mediary = null;

      // the age old 'if I have it pull out existing, if I don't make a new one'
      if (processingStorage.containsKey(doc)) {
        mediary = processingStorage.get(doc);
      } else {
        mediary =
            new ParserMediary(
                doc.name(),
                doc.commentText(),
                ParseAnnotationInstances(doc.annotations(), doc.name()));

        processingStorage.put(doc, mediary);
      }

      if (classDoc.isIncluded()) {
        // dev comment--why do enums show up as ordinary class?
        if (classDoc.isOrdinaryClass() || classDoc.isException() || classDoc.isError()) {
          mediary.addClass(ParseClass(classDoc));
        } else if (classDoc.isEnum()) {
          mediary.addEnum(ParseEnum(classDoc));
        } else if (isAnnotation(classDoc)) {
          mediary.addAnnotation(ParseAnnotation(classDoc));
        } else if (classDoc.isInterface()) {
          mediary.addInterface(ParseInterface(classDoc));
        }
      } else {
        log.debug("Skipping not-included class " + classDoc.qualifiedName());
      }
    }

    if (processingStorage.size() > 0) {
      List list = new ArrayList<Package>();

      for (ParserMediary mediary : processingStorage.values()) {
        list.add(mediary.wrapup());
      }

      rootXml.packages = (Package[]) list.toArray(new Package[] {});
    } else {
      log.warn("No packages found!");
    }

    return rootXml;
  }