public static void main(String[] args) throws IOException {
    System.out.println("Input Stream:");
    long start = System.currentTimeMillis();
    Path filename = Paths.get(args[0]);
    long crcValue = checksumInputStream(filename);
    long end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Buffered Input Stream:");
    start = System.currentTimeMillis();
    crcValue = checksumBufferedInputStream(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Random Access File:");
    start = System.currentTimeMillis();
    crcValue = checksumRandomAccessFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Mapped File:");
    start = System.currentTimeMillis();
    crcValue = checksumMappedFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");
  }
Example #2
0
 /**
  * @param file
  * @return
  * @throws IOException
  */
 static long readUnsignedLong(final ERandomAccessFile file) throws IOException {
   final long result = file.readLongE();
   if (result < 0) {
     throw new IOException(
         "Maximal file offset is "
             + Long.toHexString(Long.MAX_VALUE)
             + " given offset is "
             + Long.toHexString(result));
   }
   return result;
 }
  // Get Color as String
  public static String getColor(Color color) {
    ArrayList<String> colors = new ArrayList<String>();
    colors.add(Long.toHexString(color.getRed()));
    colors.add(Long.toHexString(color.getGreen()));
    colors.add(Long.toHexString(color.getBlue()));

    StringBuilder buffer = new StringBuilder();
    for (String c : colors) {
      if (c.length() == 1) {
        buffer.append("0");
      }
      buffer.append(c);
    }
    return ("#" + buffer.toString());
  }
Example #4
0
 public void addFile(String name, String file) throws IOException {
   if (boundary == null) {
     boundary =
         Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value.
   }
   files.put(name, file);
 }
  public static void test2() throws Exception {
    byte[] bytes =
        new byte[] {
          (byte) 0x12,
          (byte) 0x34,
          (byte) 0x56,
          (byte) 0x78,
          (byte) 0x9a,
          (byte) 0xbc,
          (byte) 0xde,
          (byte) 0xff
        };

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    BitOutputStream out = new BitOutputStream(bOut);
    for (int i = 0; i < bytes.length; i++) {
      out.writeBits(1, 1);
      out.writeBits(bytes[i], 8);
      out.writeLongBits(0x123456789abcdef0L, 64);
      out.writeLongBits(-1, 64);
      out.writeLongBits(0x80123456789abcdeL, 64);
    }
    out.close();

    byte[] toRead = bOut.toByteArray();
    System.out.println("Written length:" + toRead.length);

    ByteArrayInputStream bIn = new ByteArrayInputStream(toRead);
    BitInputStream in = new BitInputStream(bIn);
    for (int i = 0; i < bytes.length; i++) {
      int test = in.readBits(1);
      int val = in.readBits(8);
      long l1 = in.readLongBits(64);
      long l2 = in.readLongBits(64);
      long l3 = in.readLongBits(64);
      System.out.print("[" + Integer.toHexString(val) + "]");
      System.out.println(
          "("
              + Long.toHexString(l1)
              + ", "
              + Long.toHexString(l2)
              + ", "
              + Long.toHexString(l3)
              + ")");
    }
    System.out.println();
  }
Example #6
0
 protected File createTempFile(String prefex, File dir) {
   long t = System.currentTimeMillis();
   File f = null;
   do {
     String fn = prefex + Long.toHexString(t);
     t = t + 1;
     f = new File(dir, fn);
   } while (f.exists());
   return f;
 }
 private void markAndTraverse(OopHandle handle) {
   try {
     markAndTraverse(heap.newOop(handle));
   } catch (AddressException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: AddressException at 0x"
             + Long.toHexString(e.getAddress())
             + " while traversing oop at "
             + handle);
   } catch (UnknownOopException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: UnknownOopException for " + "oop at " + handle);
   }
 }
Example #8
0
  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Usage: test file");
      System.exit(1);
    }
    File f = new File(args[0]);
    // First: read just keys
    System.out.println("Loading keys...");
    KeyEntry[] entries = shuffleEntries(loadKeys(f, KEY_SAMPLING_RATIO));
    // Then build tries
    System.out.println("Building raw trie data...");
    VIntValueReader kr = new VIntValueReader(f);
    SimpleVIntTrieBuilder b = new SimpleVIntTrieBuilder(kr);
    // To re-order or not? Reordering increases speed by ~10%:
    final boolean REORDER = true;
    System.out.println("Reorder entries: " + REORDER);
    b.setReorderEntries(REORDER);
    byte[] rawTrie = b.build().serialize();
    b = null; // just ensure we can GC interemediate stuff
    TrieLookup<Long> arrayBased = new ByteArrayVIntTrieLookup(rawTrie);
    ByteBuffer buffer = ByteBuffer.allocateDirect((int) rawTrie.length);
    System.out.println("ByteBuffer: is-direct? " + buffer.isDirect());
    buffer.put(rawTrie);

    TrieLookup<Long> bufferBased = new ByteBufferVIntTrieLookup(buffer, rawTrie.length);
    VIntSpeedTest test = new VIntSpeedTest(entries);
    for (int i = 0; true; ++i) {
      long start = System.currentTimeMillis();
      TrieLookup<Long> trie;
      switch (i % 2) {
        case 1:
          trie = bufferBased;
          break;
        default:
          trie = arrayBased;
      }
      long result = test.test(trie);
      long time = System.currentTimeMillis() - start;
      System.out.println(
          "Took "
              + time
              + " msecs for "
              + trie.getClass()
              + " (result "
              + Long.toHexString(result)
              + ")");
      Thread.sleep(100L);
    }
  }
Example #9
0
  /** creates new file */
  public GlyphFile(File a_dir, String a_name, long a_unicode) throws FileNotFoundException {
    super();

    m_fileName = createFileName(a_dir, a_name);

    init(getClass().getResource(s_emptyFileName));
    setGlyphTitle(a_name);
    setUnicode(Long.toHexString(a_unicode));

    /*int eastAsianWidth = UCharacter.getIntPropertyValue(
    (int) a_unicode,
    0x1004); //UProperty.EAST_ASIAN_WIDTH);
         */
    int eastAsianWidth = 5; // ??
    if (eastAsianWidth == 5 || eastAsianWidth == 1) {
      setAdvanceWidth(k_fullWidth);
    } // if

    saveGlyphFile();
  }
Example #10
0
 /** Returns val represented by the specified number of hex digits. */
 protected static String digits(long val, int digits) {
   long hi = 1L << (digits * 4);
   return Long.toHexString(hi | (val & (hi - 1))).substring(1);
 }
Example #11
0
  private String substitute(String spec, long n) throws IOException {
    boolean escaped = false;
    byte[] str = spec.getBytes();
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < str.length; i++) {
      char c = (char) (str[i] & 0xFF);
      if (escaped) {
        sb.append(c);
        escaped = false;
      } else if (c == '\\') {
        if (i + 1 == str.length) throw new TextParseException("invalid escape character");
        escaped = true;
      } else if (c == '$') {
        boolean negative = false;
        long offset = 0;
        long width = 0;
        long base = 10;
        boolean wantUpperCase = false;
        if (i + 1 < str.length && str[i + 1] == '$') {
          // '$$' == literal '$' for backwards
          // compatibility with old versions of BIND.
          c = (char) (str[++i] & 0xFF);
          sb.append(c);
          continue;
        } else if (i + 1 < str.length && str[i + 1] == '{') {
          // It's a substitution with modifiers.
          i++;
          if (i + 1 < str.length && str[i + 1] == '-') {
            negative = true;
            i++;
          }
          while (i + 1 < str.length) {
            c = (char) (str[++i] & 0xFF);
            if (c == ',' || c == '}') break;
            if (c < '0' || c > '9') throw new TextParseException("invalid offset");
            c -= '0';
            offset *= 10;
            offset += c;
          }
          if (negative) offset = -offset;

          if (c == ',') {
            while (i + 1 < str.length) {
              c = (char) (str[++i] & 0xFF);
              if (c == ',' || c == '}') break;
              if (c < '0' || c > '9') throw new TextParseException("invalid width");
              c -= '0';
              width *= 10;
              width += c;
            }
          }

          if (c == ',') {
            if (i + 1 == str.length) throw new TextParseException("invalid base");
            c = (char) (str[++i] & 0xFF);
            if (c == 'o') base = 8;
            else if (c == 'x') base = 16;
            else if (c == 'X') {
              base = 16;
              wantUpperCase = true;
            } else if (c != 'd') throw new TextParseException("invalid base");
          }

          if (i + 1 == str.length || str[i + 1] != '}')
            throw new TextParseException("invalid modifiers");
          i++;
        }
        long v = n + offset;
        if (v < 0) throw new TextParseException("invalid offset expansion");
        String number;
        if (base == 8) number = Long.toOctalString(v);
        else if (base == 16) number = Long.toHexString(v);
        else number = Long.toString(v);
        if (wantUpperCase) number = number.toUpperCase();
        if (width != 0 && width > number.length()) {
          int zeros = (int) width - number.length();
          while (zeros-- > 0) sb.append('0');
        }
        sb.append(number);
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }