Exemplo n.º 1
0
  protected void writeIt(File uploadFile, OutputStream entityStream) throws IOException {
    InputStream inputStream = new BufferedInputStream(new FileInputStream(uploadFile));

    try {
      ProviderHelper.writeTo(inputStream, entityStream);
    } finally {
      inputStream.close();
    }
  }
  public void writeTo(
      File uploadFile,
      Class<?> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, Object> httpHeaders,
      OutputStream entityStream)
      throws IOException {
    InputStream inputStream = new BufferedInputStream(new FileInputStream(uploadFile));

    try {
      ProviderHelper.writeTo(inputStream, entityStream);
    } finally {
      inputStream.close();
    }
  }
Exemplo n.º 3
0
  public File readFrom(
      Class<File> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream)
      throws IOException {
    File downloadedFile = null;

    if (_downloadDirectory != null) {
      try {
        downloadedFile = File.createTempFile(PREFIX, SUFFIX, new File(_downloadDirectory));
      } catch (final IOException ex) {
        // could make this configurable, so we fail on fault rather than
        // default.

        System.err.println(
            "Could not bind to specified download directory "
                + _downloadDirectory
                + " so will use temp dir.");
      }
    }

    if (downloadedFile == null) downloadedFile = File.createTempFile(PREFIX, SUFFIX);

    if (NoContent.isContentLengthZero(httpHeaders)) return downloadedFile;
    OutputStream output = new BufferedOutputStream(new FileOutputStream(downloadedFile));

    try {
      ProviderHelper.writeTo(entityStream, output);
    } finally {
      output.close();
    }

    return downloadedFile;
  }