Java Code Examples for org.apache.commons.io.IOUtils.copyLarge()

The following are Jave code examples for showing how to use copyLarge() of the org.apache.commons.io.IOUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Reer   File: FileResourceConnector.java   View Source Code Vote up 6 votes
@Override
public void put(LocalResource source, URI destination) throws IOException {
    File target = getFile(destination);
    if (!target.canWrite()) {
        target.delete();
    } // if target is writable, the copy will overwrite it without requiring a delete
    GFileUtils.mkdirs(target.getParentFile());

    InputStream input = source.open();
    try {
        FileOutputStream output = new FileOutputStream(target);
        try {
            IOUtils.copyLarge(input, output);
        } finally {
            output.close();
        }
    } finally {
        input.close();
    }
}
 
Example 2
Project: known-issue   File: ExecutableMethodBuilder.java   View Source Code Vote up 6 votes
private File downloadFile(HttpResponse response) {
    File dir = new File("downloadedFiles");
    if (!dir.exists()) {
        dir.mkdir();
    }
    File outputFile = new File("downloadedFiles/temp" + RandomStringUtils.randomAlphanumeric(3));
    try {

        IOUtils.copyLarge(response.getEntity().getContent(), new FileOutputStream(outputFile));
        return outputFile;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        request.releaseConnection();
    }
}
 
Example 3
Project: jobson   File: JobResource.java   View Source Code Vote up 6 votes
private Response generateBinaryDataResponse(JobId jobId, Optional<BinaryData> maybeBinaryData) {
    if (maybeBinaryData.isPresent()) {
        final BinaryData binaryData = maybeBinaryData.get();

        final StreamingOutput body = outputStream -> {
            IOUtils.copyLarge(binaryData.getData(), outputStream);
            binaryData.getData().close();
        };

        final Response.ResponseBuilder b =
                Response.ok(body, binaryData.getMimeType())
                        .header("Content-Length", binaryData.getSizeOf());

        if (binaryData.getSizeOf() > Constants.MAX_JOB_OUTPUT_SIZE_IN_BYTES_BEFORE_DISABLING_COMPRESSION)
            b.header("Content-Encoding", "identity");

        return b.build();
    } else {
        return Response.status(404).build();
    }
}
 
Example 4
Project: lams   File: AbstractLocalFileSystemConnector.java   View Source Code Vote up 6 votes
public String fileUpload(final ResourceType type,
		final String currentFolder, final String fileName,
		final InputStream inputStream)
		throws InvalidCurrentFolderException, WriteException {
	String absolutePath = getRealUserFilesAbsolutePath(RequestCycleHandler
			.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
	File typeDir = getOrCreateResourceTypeDir(absolutePath, type);
	File currentDir = new File(typeDir, currentFolder);
	if (!currentDir.exists() || !currentDir.isDirectory())
		throw new InvalidCurrentFolderException();

	File newFile = new File(currentDir, fileName);
	File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());

	try {
		IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
	} catch (IOException e) {
		throw new WriteException();
	}
	return fileToSave.getName();
}
 
Example 5
Project: cyberduck   File: DefaultFindFeatureTest.java   View Source Code Vote up 6 votes
@Test
public void testFindLargeUpload() throws Exception {
    final B2Session session = new B2Session(
            new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
                    new Credentials(
                            System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
                    )));
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path file = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final StatusOutputStream<VersionId> out = new B2LargeUploadWriteFeature(session).write(file, new TransferStatus(), new DisabledConnectionCallback());
    IOUtils.copyLarge(new ByteArrayInputStream(RandomUtils.nextBytes(100)), out);
    out.close();
    assertTrue(new DefaultFindFeature(session).find(file));
    session.close();
}
 
Example 6
Project: fpm   File: ShapefileDownloader.java   View Source Code Vote up 6 votes
public void download(TomtomCountry country, MetalinkUrl component) {
    for (int i = 0; i < 3; i++) {
        try {
            HttpGet get = new HttpGet(component.getUrl());
            File countryDirectory = directories.get(country.getLabel());

            File downloaded = new File(countryDirectory, component.getName());
            try (InputStream content = client.execute(get).getEntity().getContent(); FileOutputStream fos = new FileOutputStream(downloaded)) {
                IOUtils.copyLarge(content, fos);
            }
            ShapefileExtractor.decompress(countryDirectory, downloaded, country.isOuterworld(), component.getType());
            downloaded.delete();
            return;
        }
        catch (IOException | ExecutionException ex) {
            log.error("Retrying.. ", ex);
        }
    }
    throw new RuntimeException("Too many retry");
}
 
Example 7
Project: fpm   File: MetalinkDownloader.java   View Source Code Vote up 6 votes
public Metalink download() throws IOException {
    HttpGet metalinkRequest = new HttpGet(
            "https://edelivery-ad.tomtom.com/automaticdownload/filter/token/" + getToken() + "/product/*/region/*/country/*/release/" + tomtomVersion + "/format/*/output/metalink/file/*");

    File outputFile = new File(outputDirectory + "/Europe." + now().toString(forPattern("ddMMyyyy-HHmm")) + ".metalink");

    log.info("Fetching metalink in path={}", outputFile.getAbsolutePath());

    try (InputStream content = client.execute(metalinkRequest).getEntity().getContent();
        FileOutputStream fos = new FileOutputStream(outputFile)) {
        IOUtils.copyLarge(content, fos);
    }
    log.info("Success!");

    return MetalinkParser.parse(new FileInputStream(outputFile));
}
 
Example 8
Project: Reer   File: AbstractExternalResource.java   View Source Code Vote up 5 votes
public void writeTo(OutputStream output) {
    try {
        InputStream input = openStream();
        try {
            IOUtils.copyLarge(input, output);
        } finally {
            input.close();
        }
    } catch (Exception e) {
        throw ResourceExceptions.getFailed(getURI(), e);
    }
}
 
Example 9
Project: Reer   File: DefaultCacheAwareExternalResourceAccessor.java   View Source Code Vote up 5 votes
@Override
public Object execute(InputStream inputStream, ExternalResourceMetaData metaData) throws IOException {
    this.metaData = metaData;
    FileOutputStream outputStream = new FileOutputStream(destination);
    try {
        IOUtils.copyLarge(inputStream, outputStream);
    } finally {
        outputStream.close();
    }
    return null;
}
 
Example 10
Project: Reer   File: RepeatableInputStreamEntity.java   View Source Code Vote up 5 votes
public void writeTo(OutputStream outstream) throws IOException {
    InputStream content = getContent();
    try {
        IOUtils.copyLarge(content, outstream);
    } finally {
        IOUtils.closeQuietly(content);
    }
}
 
Example 11
Project: Reer   File: AbstractFileTreeElement.java   View Source Code Vote up 5 votes
public void copyTo(OutputStream output) {
    try {
        InputStream inputStream = open();
        try {
            IOUtils.copyLarge(inputStream, output);
        } finally {
            inputStream.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 12
Project: galop   File: MessageBodyWriterImpl.java   View Source Code Vote up 5 votes
@Override
public void writeIdentityEntity(final InputStream inputStream, final OutputStream outputStream, final long length)
        throws IOException {

    checkNotNull(inputStream, "inputStream");
    checkNotNull(outputStream, "outputStream");
    checkNotNegative(length, "length");

    IOUtils.copyLarge(inputStream, outputStream, 0, length);

}
 
Example 13
Project: jobson   File: FilesystemJobsDAO.java   View Source Code Vote up 5 votes
private void writeJobOutputToDisk(JobOutput jobOutput, Path outputPath) {
    try {
        IOUtils.copyLarge(jobOutput.getData().getData(), new FileOutputStream(outputPath.toFile(), false));
        jobOutput.getData().getData().close();
    } catch (IOException ex) {
        throw new RuntimeException(outputPath + ": cannot write: " + ex);
    }
}
 
Example 14
Project: galop   File: MessageBodyWriterImpl.java   View Source Code Vote up 3 votes
private boolean handleChunk(final InputStream inputStream, final OutputStream outputStream) throws IOException {

        long chunkSize = readChunkSize(inputStream, outputStream);
        boolean lastChunk = chunkSize == 0;

        if (!lastChunk) {
            // Copy chunk data and the following CRLF.
            IOUtils.copyLarge(inputStream, outputStream, 0, chunkSize + 2);
        }

        return lastChunk;

    }