Exemplo n.º 1
0
  public Transfer writeToCache(final ConcreteResource resource, final String content)
      throws IOException {
    if (content == null) {
      throw new IOException("Content is empty!");
    }

    final Transfer tx = getTransfer(resource);
    OutputStream out = null;
    try {
      out = tx.openOutputStream(TransferOperation.UPLOAD, false);
      out.write(content.getBytes());
    } finally {
      IOUtils.closeQuietly(out);
    }

    return tx;
  }
Exemplo n.º 2
0
  public Transfer writeClasspathResourceToCache(
      final ConcreteResource resource, final String cpResource) throws IOException {
    final InputStream in =
        Thread.currentThread().getContextClassLoader().getResourceAsStream(cpResource);
    if (in == null) {
      throw new IOException("Classpath resource not found: " + cpResource);
    }

    final Transfer tx = getTransfer(resource);
    OutputStream out = null;
    try {
      out = tx.openOutputStream(TransferOperation.UPLOAD, false);
      IOUtils.copy(in, out);
    } finally {
      IOUtils.closeQuietly(in);
      IOUtils.closeQuietly(out);
    }

    return tx;
  }