本文整理汇总了Java中org.apache.commons.io.IOUtils.copyLarge方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copyLarge方法的具体用法?Java IOUtils.copyLarge怎么用?Java IOUtils.copyLarge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copyLarge方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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();
}
}
示例2: downloadFile
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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();
}
}
示例3: generateBinaryDataResponse
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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();
}
}
示例4: fileUpload
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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();
}
示例5: testFindLargeUpload
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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();
}
示例6: download
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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");
}
示例7: download
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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));
}
示例8: writeTo
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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);
}
}
示例9: execute
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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;
}
示例10: writeTo
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void writeTo(OutputStream outstream) throws IOException {
InputStream content = getContent();
try {
IOUtils.copyLarge(content, outstream);
} finally {
IOUtils.closeQuietly(content);
}
}
示例11: copyTo
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void copyTo(OutputStream output) {
try {
InputStream inputStream = open();
try {
IOUtils.copyLarge(inputStream, output);
} finally {
inputStream.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例12: writeIdentityEntity
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@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);
}
示例13: writeJobOutputToDisk
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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);
}
}
示例14: handleChunk
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
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;
}