예제 #1
0
  @Test(groups = TestGroup.UNIT)
  public void roundTrip() throws IOException {
    InputStream source1 = new ByteArrayInputStream(s_json.getBytes());
    ByteArrayOutputStream sink1 = new ByteArrayOutputStream();
    Compressor.compressStream(source1, sink1);

    InputStream source2 = new ByteArrayInputStream(sink1.toByteArray());
    ByteArrayOutputStream sink2 = new ByteArrayOutputStream();
    Compressor.decompressStream(source2, sink2);
    assertEquals(s_json, sink2.toString());
  }
 /** Create the application. */
 public Outside() {
   initialize();
   mcu.configurePins(TXDPin, RXDPin, Compressor_MCU_Pin);
   mcu.start();
   max485.start();
   compressor.start();
 }
예제 #3
0
 public static void main(String[] args) throws IOException {
   InputStream source1 =
       new ByteArrayInputStream(new JSONArray(randomObjects()).toString().getBytes());
   ByteArrayOutputStream sink1 = new ByteArrayOutputStream();
   System.out.println(s_json);
   Compressor.compressStream(source1, sink1);
   System.out.println("JSON size: " + s_json.length());
   System.out.println("compressed size: " + sink1.size());
   System.out.println("ratio: " + ((double) sink1.size() / (double) s_json.length()));
 }
예제 #4
0
  @Override
  public UploadResult uploadBackup(
      Exhibitor exhibitor,
      BackupMetaData backup,
      File source,
      final Map<String, String> configValues)
      throws Exception {
    List<BackupMetaData> availableBackups = getAvailableBackups(exhibitor, configValues);
    if (availableBackups.contains(backup)) {
      return UploadResult.DUPLICATE;
    }

    RetryPolicy retryPolicy = makeRetryPolicy(configValues);
    Throttle throttle = makeThrottle(configValues);

    String key = toKey(backup);
    InitiateMultipartUploadRequest initRequest =
        new InitiateMultipartUploadRequest(configValues.get(CONFIG_BUCKET.getKey()), key);
    InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest);

    CompressorIterator compressorIterator = compressor.compress(source);
    try {
      List<PartETag> eTags = Lists.newArrayList();
      int index = 0;
      for (; ; ) {
        ByteBuffer chunk = compressorIterator.next();
        if (chunk == null) {
          break;
        }
        throttle.throttle(chunk.limit());

        PartETag eTag = uploadChunkWithRetry(chunk, initResponse, index++, retryPolicy);
        eTags.add(eTag);
      }

      completeUpload(initResponse, eTags);
    } catch (Exception e) {
      abortUpload(initResponse);
      throw e;
    } finally {
      Closeables.closeQuietly(compressorIterator);
    }

    UploadResult result = UploadResult.SUCCEEDED;
    for (BackupMetaData existing : availableBackups) {
      if (existing.getName().equals(backup.getName())) {
        deleteBackup(exhibitor, existing, configValues);
        result = UploadResult.REPLACED_OLD_VERSION;
      }
    }
    return result;
  }
예제 #5
0
파일: Main.java 프로젝트: NCIP/calims
  static void processFiles(Context cx, String[] files) throws IOException {
    StringBuffer cout = new StringBuffer();
    if (files.length > 0) {
      for (int i = 0; i < files.length; i++) {
        try {
          String source = (String) readFileOrUrl(files[i], true);
          cout.append(Compressor.compressScript(source, 0, 1, escapeUnicode, stripConsole));
        } catch (IOException ex) {
          // continue processing files
        }
      }
    } else {
      byte[] data = Kit.readStream(global.getIn(), 4096);
      // Convert to String using the default encoding
      String source = new String(data);
      if (source != null) {
        cout.append(Compressor.compressScript(source, 0, 1, escapeUnicode, stripConsole));
      }
    }

    global.getOut().println(cout);
  }
예제 #6
0
  @Override
  public void downloadBackup(
      Exhibitor exhibitor,
      BackupMetaData backup,
      File destination,
      Map<String, String> configValues)
      throws Exception {
    S3Object object = s3Client.getObject(configValues.get(CONFIG_BUCKET.getKey()), toKey(backup));

    long startMs = System.currentTimeMillis();
    RetryPolicy retryPolicy = makeRetryPolicy(configValues);
    int retryCount = 0;
    boolean done = false;
    while (!done) {
      Throttle throttle = makeThrottle(configValues);
      InputStream in = null;
      FileOutputStream out = null;
      try {
        out = new FileOutputStream(destination);
        in = object.getObjectContent();

        FileChannel channel = out.getChannel();
        CompressorIterator compressorIterator = compressor.decompress(in);
        for (; ; ) {
          ByteBuffer bytes = compressorIterator.next();
          if (bytes == null) {
            break;
          }

          throttle.throttle(bytes.limit());
          channel.write(bytes);
        }

        done = true;
      } catch (Exception e) {
        if (!retryPolicy.allowRetry(retryCount++, System.currentTimeMillis() - startMs)) {
          done = true;
        }
      } finally {
        Closeables.closeQuietly(in);
        Closeables.closeQuietly(out);
      }
    }
  }
 /**
  * stop()
  *
  * <p>stops compressing air
  */
 public void stop() {
   compressor.stop();
 }
 /**
  * start()
  *
  * <p>starts compressing air
  */
 public void start() {
   compressor.start();
 }