public static void main(String[] args) throws IOException {
    // Get input html
    StringBuffer sb = new StringBuffer();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    for (String str = in.readLine(); str != null; str = in.readLine()) {
      sb.append("\n" + str);
    }
    String html = sb.toString();

    // Match all the questions
    Matcher matcher =
        Pattern.compile(
                "<\\s*div\\s+class\\s*=\\s*\"question-summary\"\\s*id\\s*=\\s*\"question-summary-(?<id>\\d+)\"\\s*>"
                    + ".*?<\\s*div\\s+class\\s*=\\s*\"summary\"\\s*>"
                    + ".*?<\\s*a\\s+.*?class\\s*=\\s*\"question-hyperlink\"\\s*>"
                    + "(?<title>.*?)"
                    + "</\\s*a\\s*>.*?<\\s*div\\s+class\\s*=\\s*\"user-action-time\"\\s*>"
                    + ".*?<\\s*span\\s+.*?>(?<time>.*?)</\\s*span\\s*>",
                Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(html);

    // Output the information
    while (matcher.find()) {
      String id = matcher.group("id");
      String title = matcher.group("title");
      String time = matcher.group("time");
      System.out.println(id + ";" + title + ";" + time);
    }
  }
 public String parse(String format) {
   StringBuffer buffer = new StringBuffer();
   Matcher m = formatPattern.matcher(format);
   while (m.find()) m.appendReplacement(buffer, getFormatSpecifierValue(m.group()));
   m.appendTail(buffer);
   return buffer.toString();
 }
    /**
     * Create a Transferable to use as the source for a data transfer.
     *
     * @param c The component holding the data to be transfered. This argument is provided to enable
     *     sharing of TransferHandlers by multiple components.
     * @return The representation of the data to be transfered.
     */
    protected Transferable createTransferable(JComponent c) {
      Object[] values = null;
      if (c instanceof JList) {
        values = ((JList) c).getSelectedValues();
      } else if (c instanceof JTable) {
        JTable table = (JTable) c;
        int[] rows = table.getSelectedRows();
        if (rows != null) {
          values = new Object[rows.length];
          for (int i = 0; i < rows.length; i++) {
            values[i] = table.getValueAt(rows[i], 0);
          }
        }
      }
      if (values == null || values.length == 0) {
        return null;
      }

      StringBuffer plainBuf = new StringBuffer();
      StringBuffer htmlBuf = new StringBuffer();

      htmlBuf.append("<html>\n<body>\n<ul>\n");

      for (Object obj : values) {
        String val = ((obj == null) ? "" : obj.toString());
        plainBuf.append(val + "\n");
        htmlBuf.append("  <li>" + val + "\n");
      }

      // remove the last newline
      plainBuf.deleteCharAt(plainBuf.length() - 1);
      htmlBuf.append("</ul>\n</body>\n</html>");

      return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
    }
Beispiel #4
0
  /**
   * Leave only the value for RCS keywords.
   *
   * <p>For example, <code>$Revision: 1.1 $</code> becomes <code>1.0</code>.
   */
  public String replaceRcsKeywords(String text) {
    if (matcher == null) {
      matcher =
          Pattern.compile(
                  "\\$(Author|Date|Header|Id|Locker|Log|Name|RCSFile|Revision|Source|State): (.+?) \\$")
              .matcher(text);
    } else {
      matcher.reset(text);
    }

    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
      String string = matcher.group(2);

      // For the Date: keyword, have a shot at reformatting string
      if ("Date".equals(matcher.group(1))) {
        try {
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = dateFormat.parse(string);
          string = date.toString();
        } catch (ParseException e) {
        } // if we can't parse, return unchanged
      }

      matcher.appendReplacement(buffer, string);
    }
    matcher.appendTail(buffer);
    return buffer.toString();
  }
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append(super.toString());
    sb.append('\n');
    sb.append("String 1: " + string1Length + " String 2: " + string2Length);

    return sb.toString();
  }
Beispiel #6
0
 public static String MD5(String in) throws Throwable {
   MessageDigest md = MessageDigest.getInstance("MD5");
   byte[] array = md.digest(in.getBytes());
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < array.length; ++i) {
     sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
   }
   return sb.toString();
 }
Beispiel #7
0
  public static String cleanText(String text) {
    StringBuffer string = new StringBuffer(text.length());
    char chars[] = text.toCharArray();
    for (int x = 0; x < chars.length; x++) {
      if (chars[x] != 1 && chars[x] != 2) string.append(chars[x]);
    }

    return string.toString();
  }
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Union (" + unionTypes.size() + "): ");
   for (InferredType it : unionTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Struct: ");
   for (InferredType it : structTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
Beispiel #10
0
  public static void main(String[] args) throws Exception {
    Reader trainingFile = null;

    // Process arguments
    int restArgs = commandOptions.processOptions(args);

    // Check arguments
    if (restArgs != args.length) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Unexpected arg " + args[restArgs]);
    }
    if (trainFileOption.value == null) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Expected --train-file FILE");
    }
    if (modelFileOption.value == null) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Expected --model-file FILE");
    }

    // Get the CRF structure specification.
    ZipFile zipFile = new ZipFile(modelFileOption.value);
    ZipEntry zipEntry = zipFile.getEntry("crf-info.xml");
    CRFInfo crfInfo = new CRFInfo(zipFile.getInputStream(zipEntry));

    StringBuffer crfInfoBuffer = new StringBuffer();
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));
    String line;
    while ((line = reader.readLine()) != null) {
      crfInfoBuffer.append(line).append('\n');
    }
    reader.close();

    // Create the CRF, and train it.
    CRF4 crf = createCRF(trainFileOption.value, crfInfo);

    // Create a new zip file for our output.  This will overwrite
    // the file we used for input.
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(modelFileOption.value));

    // Copy the CRF info xml to the output zip file.
    zos.putNextEntry(new ZipEntry("crf-info.xml"));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos));
    writer.write(crfInfoBuffer.toString());
    writer.flush();
    zos.closeEntry();

    // Save the CRF classifier model to the output zip file.
    zos.putNextEntry(new ZipEntry("crf-model.ser"));
    ObjectOutputStream oos = new ObjectOutputStream(zos);
    oos.writeObject(crf);
    oos.flush();
    zos.closeEntry();
    zos.close();
  }
  public String formatXMLdata(String xmlData) {

    Pattern p = Pattern.compile("(<|&|\'|\"|>)");
    Matcher m = p.matcher(xmlData);
    StringBuffer strBuf = new StringBuffer();
    while (m.find()) {
      m.appendReplacement(strBuf, (String) xmlHashMap.get(m.group()));
    }
    m.appendTail(strBuf);
    return strBuf.toString();
  }
 public String getDocString() {
   StringBuffer buf = new StringBuffer();
   buf.append("Example data: ");
   for (Iterator<String> it = sampleStrs.iterator(); it.hasNext(); ) {
     String tokStr = it.next();
     buf.append("'" + tokStr + "'");
     if (it.hasNext()) {
       buf.append(", ");
     }
   }
   return buf.toString();
 }
Beispiel #13
0
 /**
  * Converts the path back to the string representation.
  *
  * @return
  */
 public String toString(Path path) {
   StringBuffer buffer = new StringBuffer();
   boolean first = true;
   for (Part p : path.parts) {
     if (!first) {
       buffer.append(path_seperator);
     }
     buffer.append(p.toString(this));
     first = false;
   }
   return buffer.toString();
 }
 /** Writes the body of the valid method to fileText. */
 private void writeValidBody() {
   if (vars.length > 0) {
     fileText.append("    return (" + vars[0].getFieldName() + " != null)");
     for (int i = 1; i < vars.length; i++) {
       fileText.append(" && (" + vars[0].getFieldName() + " != null)");
     }
     add(";");
   } else {
     add("    /* no variables were found */");
     add("    return false;");
   }
 }
  void findRemoveDirectives(boolean clean) {
    // if ( clean ) editor.startCompoundEdit();

    Sketch sketch = editor.getSketch();
    for (int i = 0; i < sketch.getCodeCount(); i++) {
      SketchCode code = sketch.getCode(i);
      String program = code.getProgram();
      StringBuffer buffer = new StringBuffer();

      Matcher m = pjsPattern.matcher(program);
      while (m.find()) {
        String mm = m.group();

        // TODO this urgently needs tests ..

        /* remove framing */
        mm = mm.replaceAll("^\\/\\*\\s*@pjs", "").replaceAll("\\s*\\*\\/\\s*$", "");
        /* fix multiline nice formatting */
        mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*,[\\s]*[\\n\\r]+", "$1,");
        /* fix multiline version without semicolons */
        mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*[\\n\\r]+", "$1;");
        mm = mm.replaceAll("\n", " ").replaceAll("\r", " ");

        // System.out.println(mm);

        if (clean) {
          m.appendReplacement(buffer, "");
        } else {
          String[] directives = mm.split(";");
          for (String d : directives) {
            // System.out.println(d);
            parseDirective(d);
          }
        }
      }

      if (clean) {
        m.appendTail(buffer);

        // TODO: not working!
        code.setProgram(buffer.toString());
        code.setModified(true);
      }
    }

    if (clean) {
      // editor.stopCompoundEdit();
      editor.setText(sketch.getCurrentCode().getProgram());
      sketch.setModified(false);
      sketch.setModified(true);
    }
  }
 public void addFailure(Test test, AssertionFailedError t) {
   StringBuffer sb = new StringBuffer();
   sb.append(test.toString());
   sb.append("\n");
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw, true));
   sb.append(sw.toString());
   Log.getLogWriter().severe("zzzzzFAILURE IN " + test, t);
   // reportFailure(test, sb.toString());
   lastFailClass = getClassName(test);
   lastFailMethod = getMethodName(test);
   lastThrowable = t;
 }
Beispiel #17
0
 public StringBuffer construct_lucene_solr(StringBuffer result, SolrDocument d) {
   for (String field : (d.getFieldNames())) {
     if ((!field.endsWith("_str")) && (!field.equalsIgnoreCase("fullrecord"))) {
       Iterator j = d.getFieldValues(field).iterator();
       while (j.hasNext()) {
         result.append("<" + field + ">");
         result.append(helpers.xmlEncode((String) j.next().toString()));
         field = field.split(" ")[0];
         result.append("</" + field + ">");
       }
     }
   }
   return (result);
 }
Beispiel #18
0
 private String presub(String query, Object[] params) {
   if (params == null) return query;
   StringBuffer buf = new StringBuffer();
   Matcher matcher = PRE_SUB_PATTERN.matcher(query);
   while (matcher.find()) {
     matcher.appendReplacement(
         buf,
         ((String) params[Integer.parseInt(matcher.group(1)) - 1])
             .replace("\\", "\\\\")
             .replace("$", "\\$"));
   }
   matcher.appendTail(buf);
   return buf.toString();
 }
  void applyDirectives() {
    findRemoveDirectives(true);

    StringBuffer buffer = new StringBuffer();
    String head = "", toe = "; \n";

    if (crispBox.isSelected()) buffer.append(head + "crisp=true" + toe);
    if (!fontField.getText().trim().equals(""))
      buffer.append(head + "font=\"" + fontField.getText().trim() + "\"" + toe);
    if (globalKeyEventsBox.isSelected()) buffer.append(head + "globalKeyEvents=true" + toe);
    if (pauseOnBlurBox.isSelected()) buffer.append(head + "pauseOnBlur=true" + toe);
    if (!preloadField.getText().trim().equals(""))
      buffer.append(head + "preload=\"" + preloadField.getText().trim() + "\"" + toe);
    /*if ( transparentBox.isSelected() )
    buffer.append( head + "transparent=true" + toe );*/

    Sketch sketch = editor.getSketch();
    SketchCode code = sketch.getCode(0); // first tab
    if (buffer.length() > 0) {
      code.setProgram("/* @pjs " + buffer.toString() + " */\n\n" + code.getProgram());
      if (sketch.getCurrentCode() == code) // update textarea if on first tab
      {
        editor.setText(sketch.getCurrentCode().getProgram());
        editor.setSelection(0, 0);
      }

      sketch.setModified(false);
      sketch.setModified(true);
    }
  }
  /**
   * Removes all section headers.
   *
   * @param markup the text to be stripped
   * @return the stripped markup
   */
  public static String stripHeadings(String markup) {
    Pattern p = Pattern.compile("(={2,})([^=]+)(\\1)");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      sb.append(markup.substring(lastIndex, m.start()));
      lastIndex = m.end();
    }

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
  /*
     String formatStringWordwrap(String output,int colWidth,char fillchar,String appendStr)
     {
        int beginIndex,endIndex;
        String valueStr;

        if (output == null)
        {
           return null;
        }

        // This is the case where the length of the value exceeds the
        // column width
        if ((appendStr !=null) && (appendStr.length()> colWidth-output.length()))
        {
           //print atleast five fill characters
           int labelWidth = output.length() + 5;
           StringBuffer blankOutput = new StringBuffer();
           for (int i=0;i<labelWidth;i++)
              blankOutput.append(' ');

           output=formatString(output,labelWidth,fillchar);

           //break the value into multiple strings to print
           //on separate lines
           colWidth = colWidth-labelWidth;
           for (beginIndex=0,endIndex=colWidth;
              endIndex<=appendStr.length();
              beginIndex=endIndex,endIndex+=colWidth)
           {
              valueStr = appendStr.substring(beginIndex,endIndex);
              if (beginIndex==0)
                 output+=valueStr;
              else
                 output = output + SessionDefaults.lineSeperator + blankOutput + valueStr ;

           }
           if (endIndex > appendStr.length())
              output = output + SessionDefaults.lineSeperator + blankOutput + appendStr.substring(beginIndex);

           return output;
        }

        if (appendStr != null)
        {
           colWidth=colWidth - appendStr.length();
        }

        output=formatString(output,colWidth,fillchar);

        if (appendStr != null && output != null)
        {
           output+=appendStr;
        }


        return output;

     }
  */
  String formatString(String output, int colWidth, char fillchar) {
    StringBuffer outBuffer = null;

    if (output == null) {
      return null;
    }

    outBuffer = new StringBuffer(output);

    if (outBuffer.length() <= colWidth) {
      for (int i = outBuffer.length(); i < colWidth; i++) outBuffer.append(fillchar);
    }

    return outBuffer.toString();
  }
Beispiel #22
0
 /** Receive notification of character data inside an element. */
 @Override
 public void characters(char ch[], int start, int len) {
   while (len > 0 && Character.isWhitespace(ch[start])) {
     ++start;
     --len;
   }
   while (len > 0 && Character.isWhitespace(ch[start + len - 1])) {
     --len;
   }
   if (len > 0) {
     if (_chars.length() > 0) {
       _chars.append(' ');
     }
     _chars.append(ch, start, len);
   }
 }
  private String blankSectionHeaders(String markup, StringBuffer context) {

    Pattern p = Pattern.compile("(={2,})([^=]+)\\1");
    Matcher m = p.matcher(markup);

    int lastPos = 0;
    StringBuilder sb = new StringBuilder();

    while (m.find()) {
      sb.append(markup.substring(lastPos, m.start()));
      sb.append(getSpaceString(m.group().length()));

      String title = m.group(2).trim();

      if (!title.equalsIgnoreCase("see also")
          && !title.equalsIgnoreCase("external links")
          && !title.equalsIgnoreCase("references")
          && !title.equalsIgnoreCase("further reading")) context.append("\n").append(title);

      lastPos = m.end();
    }

    sb.append(markup.substring(lastPos));
    return sb.toString();
  }
Beispiel #24
0
  /**
   * Finds the original field name(s), appending the first one to the out line, and any additional
   * alternatives to the extra lines.
   */
  private void originalFieldName(
      String className,
      String obfuscatedFieldName,
      String type,
      StringBuffer outLine,
      List extraOutLines) {
    int extraIndent = -1;

    // Class name -> obfuscated field names.
    Map fieldMap = (Map) classFieldMap.get(className);
    if (fieldMap != null) {
      // Obfuscated field names -> fields.
      Set fieldSet = (Set) fieldMap.get(obfuscatedFieldName);
      if (fieldSet != null) {
        // Find all matching fields.
        Iterator fieldInfoIterator = fieldSet.iterator();
        while (fieldInfoIterator.hasNext()) {
          FieldInfo fieldInfo = (FieldInfo) fieldInfoIterator.next();
          if (fieldInfo.matches(type)) {
            // Is this the first matching field?
            if (extraIndent < 0) {
              extraIndent = outLine.length();

              // Append the first original name.
              if (verbose) {
                outLine.append(fieldInfo.type).append(' ');
              }
              outLine.append(fieldInfo.originalName);
            } else {
              // Create an additional line with the proper
              // indentation.
              StringBuffer extraBuffer = new StringBuffer();
              for (int counter = 0; counter < extraIndent; counter++) {
                extraBuffer.append(' ');
              }

              // Append the alternative name.
              if (verbose) {
                extraBuffer.append(fieldInfo.type).append(' ');
              }
              extraBuffer.append(fieldInfo.originalName);

              // Store the additional line.
              extraOutLines.add(extraBuffer);
            }
          }
        }
      }
    }

    // Just append the obfuscated name if we haven't found any matching
    // fields.
    if (extraIndent < 0) {
      outLine.append(obfuscatedFieldName);
    }
  }
 static String combineDummy(String inv, String daikonStr, String esc, String simplify) {
   StringBuffer combined = new StringBuffer(inv);
   combined.append(lineSep + "\tDAIKON_FORMAT ");
   combined.append(daikonStr);
   combined.append(lineSep + "\tESC_FORMAT ");
   combined.append(esc);
   combined.append(lineSep + "\tSIMPLIFY_FORMAT ");
   combined.append(simplify);
   return combined.toString();
 }
Beispiel #26
0
 public static void main(String[] args) throws Exception {
   // Create a pattern to match cat
   Pattern p = Pattern.compile("cat");
   // Create a matcher with an input string
   Matcher m = p.matcher("one cat," + " two cats in the yard");
   StringBuffer sb = new StringBuffer();
   boolean result = m.find();
   // Loop through and create a new String
   // with the replacements
   while (result) {
     m.appendReplacement(sb, "dog");
     result = m.find();
   }
   // Add the last segment of input to
   // the new String
   m.appendTail(sb);
   System.out.println(sb.toString());
 }
  protected void setupScoreBoardValues() {
    new ScoreBoardValue(
        "%sbto", "ScoreBoard Timeout Owner", getScoreBoard(), ScoreBoard.EVENT_TIMEOUT_OWNER) {
      public String getValue() {
        return getScoreBoard().getTimeoutOwner();
      }
    };
    new ScoreBoardValue(
        "%sbip", "ScoreBoard Is In Period", getScoreBoard(), ScoreBoard.EVENT_IN_PERIOD) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isInPeriod());
      }
    };
    new ScoreBoardValue(
        "%sbio", "ScoreBoard Is In Overtime", getScoreBoard(), ScoreBoard.EVENT_IN_OVERTIME) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isInOvertime());
      }
    };
    new ScoreBoardValue(
        "%sbos", "ScoreBoard Is Score Official", getScoreBoard(), ScoreBoard.EVENT_OFFICIAL_SCORE) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isOfficialScore());
      }
    };

    setupTeamValues("1", Team.ID_1);
    setupTeamValues("2", Team.ID_2);
    setupClockValues("p", Clock.ID_PERIOD);
    setupClockValues("j", Clock.ID_JAM);
    setupClockValues("l", Clock.ID_LINEUP);
    setupClockValues("t", Clock.ID_TIMEOUT);
    setupClockValues("i", Clock.ID_INTERMISSION);

    StringBuffer patternBuffer = new StringBuffer();
    Iterator<String> patterns = scoreBoardValues.keySet().iterator();
    while (patterns.hasNext()) patternBuffer.append(patterns.next() + "|");
    String specifiersRegex = patternBuffer.toString().replaceAll("[|]$", "");
    formatPattern = Pattern.compile(specifiersRegex);
    eventPattern = Pattern.compile("^\\s*(" + specifiersRegex + ")");
    conditionPattern =
        Pattern.compile("(" + specifiersRegex + ")(?:(" + comparatorRegex + ")(\\S+))?");
  }
  /**
   * Removes anything at the start of the markup that is indented. Normally this indicates notes
   * that the author should have used a template for, such as a "For other uses, see ****" note.
   *
   * @param markup the text to be stripped
   * @return the stripped markup
   */
  public static String stripIndentedStart(String markup) {

    Pattern p = Pattern.compile("(.*?)\n", Pattern.DOTALL);
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int newStart = 0;

    while (m.find()) {
      // System.out.println(" - \"" + m.group() + "\"\n\n") ;

      if (m.group().matches("(?s)([\\s\\W]*)([\\:\\*]+)(.*)") || m.group().matches("\\W*"))
        newStart = m.end();
      else break;
    }

    sb.append(markup.substring(newStart));
    return sb.toString();
  }
  /**
   * Strips all links from the given markup; anything like [[this]] is replaced. If it is a link to
   * a wikipedia article, then it is replaced with its anchor text. Only links to images are treated
   * differently: they are discarded entirely.
   *
   * <p>You may want to first strip non-article links, isolated links, category links etc before
   * calling this method.
   *
   * @param markup the text to be stripped
   * @return the stripped text
   */
  public static String stripLinks(String markup) {

    HashSet<String> discardPrefixes = new HashSet<String>();
    discardPrefixes.add("image");

    Vector<Integer> linkStack = new Vector<Integer>();

    Pattern p = Pattern.compile("(\\[\\[|\\]\\])");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      String tag = markup.substring(m.start(), m.end());

      if (tag.equals("[[")) linkStack.add(m.start());
      else {
        if (!linkStack.isEmpty()) {
          int linkStart = linkStack.lastElement();
          linkStack.remove(linkStack.size() - 1);

          if (linkStack.isEmpty()) {
            sb.append(markup.substring(lastIndex, linkStart));

            // we have the whole link, with other links nested inside if it's an image
            String linkMarkup = markup.substring(linkStart + 2, m.start());
            sb.append(stripLink(linkMarkup, discardPrefixes, false));

            lastIndex = m.end();
          }
        }
      }
    }

    if (!linkStack.isEmpty()) {
      System.err.println(
          "MarkupStripper | Warning: links were not well formed, so we cannot guarantee that they were stripped out correctly. ");
    }

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
Beispiel #30
0
  /*
   * Transform the hexadecimal long output into the equivalent
   * hexadecimal double value.
   */
  static String hexLongStringtoHexDoubleString(String transString) {
    transString = transString.toLowerCase();

    String zeros = "";
    StringBuffer result = new StringBuffer(24);

    for (int i = 0; i < (16 - transString.length()); i++, zeros += "0") ;
    transString = zeros + transString;

    // assert transString.length == 16;

    char topChar;
    // Extract sign
    if ((topChar = transString.charAt(0)) >= '8') { // 8, 9, a, A, b, B, ...
      result.append("-");
      // clear sign bit
      transString =
          Character.toString(Character.forDigit(Character.digit(topChar, 16) - 8, 16))
              + transString.substring(1, 16);
    }

    // check for NaN and infinity
    String signifString = transString.substring(3, 16);

    if (transString.substring(0, 3).equals("7ff")) {
      if (signifString.equals("0000000000000")) {
        result.append("Infinity");
      } else result.append("NaN");
    } else { // finite value
      // Extract exponent
      int exponent = Integer.parseInt(transString.substring(0, 3), 16) - DoubleConsts.EXP_BIAS;
      result.append("0x");

      if (exponent == DoubleConsts.MIN_EXPONENT - 1) { // zero or subnormal
        if (signifString.equals("0000000000000")) {
          result.append("0.0p0");
        } else {
          result.append(
              "0." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p-1022");
        }
      } else { // normal value
        result.append(
            "1." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p" + exponent);
      }
    }
    return result.toString();
  }