コード例 #1
0
ファイル: ExhaustiveTest.java プロジェクト: icu-project/icu4j
  private void myTest(char[] chars, int len) {
    UnicodeCompressor myCompressor = new UnicodeCompressor();
    UnicodeDecompressor myDecompressor = new UnicodeDecompressor();

    // variables for my compressor
    int myByteCount = 0;
    int myCharCount = 0;
    int myCompressedSize = Math.max(512, 3 * len);
    byte[] myCompressed = new byte[myCompressedSize];
    int myDecompressedSize = Math.max(2, 2 * len);
    char[] myDecompressed = new char[myDecompressedSize];
    int[] unicharsRead = new int[1];
    int[] bytesRead = new int[1];

    myByteCount =
        myCompressor.compress(chars, 0, len, unicharsRead, myCompressed, 0, myCompressedSize);

    myCharCount =
        myDecompressor.decompress(
            myCompressed, 0, myByteCount, bytesRead, myDecompressed, 0, myDecompressedSize);

    if (logDiffs(chars, len, myDecompressed, myCharCount) == false) {
      logln(len + " chars ===> " + myByteCount + " bytes ===> " + myCharCount + " chars");
    } else {
      logln("Compressed:");
      printBytes(myCompressed, myByteCount);
      errln("Iterative test failed");
    }
  }
コード例 #2
0
ファイル: ExhaustiveTest.java プロジェクト: icu-project/icu4j
 private void simpleTest(String s) throws Exception {
   byte[] compressed = UnicodeCompressor.compress(s);
   String res = UnicodeDecompressor.decompress(compressed);
   if (logDiffs(s.toCharArray(), s.length(), res.toCharArray(), res.length()) == false) {
     logln(
         s.length()
             + " chars ===> "
             + compressed.length
             + " bytes ===> "
             + res.length()
             + " chars");
   } else {
     logln("Compressed:");
     printBytes(compressed, compressed.length);
     errln("testSimple did not compress correctly");
   }
 }
コード例 #3
0
ファイル: ExhaustiveTest.java プロジェクト: icu-project/icu4j
  private void myMultipassTest(char[] chars, int len) throws Exception {
    UnicodeCompressor myCompressor = new UnicodeCompressor();
    UnicodeDecompressor myDecompressor = new UnicodeDecompressor();

    // variables for my compressor

    // for looping
    int byteBufferSize = 4; // Math.max(4, len / 4);
    byte[] byteBuffer = new byte[byteBufferSize];
    // real target
    int compressedSize = Math.max(512, 3 * len);
    byte[] compressed = new byte[compressedSize];

    // for looping
    int unicharBufferSize = 2; // byteBufferSize;
    char[] unicharBuffer = new char[unicharBufferSize];
    // real target
    int decompressedSize = Math.max(2, 2 * len);
    char[] decompressed = new char[decompressedSize];

    int bytesWritten = 0;
    int unicharsWritten = 0;

    int[] unicharsRead = new int[1];
    int[] bytesRead = new int[1];

    int totalCharsCompressed = 0;
    int totalBytesWritten = 0;

    int totalBytesDecompressed = 0;
    int totalCharsWritten = 0;

    // not used boolean err = false;

    // perform the compression in a loop
    do {

      // do the compression
      bytesWritten =
          myCompressor.compress(
              chars, totalCharsCompressed, len, unicharsRead, byteBuffer, 0, byteBufferSize);

      // copy the current set of bytes into the target buffer
      System.arraycopy(byteBuffer, 0, compressed, totalBytesWritten, bytesWritten);

      // update the no. of characters compressed
      totalCharsCompressed += unicharsRead[0];

      // update the no. of bytes written
      totalBytesWritten += bytesWritten;

      /*System.out.logln("Compression pass complete.  Compressed "
      + unicharsRead[0] + " chars into "
      + bytesWritten + " bytes.");*/
    } while (totalCharsCompressed < len);

    if (totalCharsCompressed != len) {
      errln(
          "ERROR: Number of characters compressed("
              + totalCharsCompressed
              + ") != len("
              + len
              + ")");
    } else {
      logln("MP: " + len + " chars ===> " + totalBytesWritten + " bytes.");
    }

    // perform the decompression in a loop
    do {

      // do the decompression
      unicharsWritten =
          myDecompressor.decompress(
              compressed,
              totalBytesDecompressed,
              totalBytesWritten,
              bytesRead,
              unicharBuffer,
              0,
              unicharBufferSize);

      // copy the current set of chars into the target buffer
      System.arraycopy(unicharBuffer, 0, decompressed, totalCharsWritten, unicharsWritten);

      // update the no. of bytes decompressed
      totalBytesDecompressed += bytesRead[0];

      // update the no. of chars written
      totalCharsWritten += unicharsWritten;

      /*System.out.logln("Decompression pass complete.  Decompressed "
      + bytesRead[0] + " bytes into "
      + unicharsWritten + " chars.");*/
    } while (totalBytesDecompressed < totalBytesWritten);

    if (totalBytesDecompressed != totalBytesWritten) {
      errln(
          "ERROR: Number of bytes decompressed("
              + totalBytesDecompressed
              + ") != totalBytesWritten("
              + totalBytesWritten
              + ")");
    } else {
      logln("MP: " + totalBytesWritten + " bytes ===> " + totalCharsWritten + " chars.");
    }

    if (logDiffs(chars, len, decompressed, totalCharsWritten)) {
      errln("ERROR: buffer contents incorrect");
    }
  }