本文整理匯總了Java中org.apache.poi.util.IOUtils.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils.copy方法的具體用法?Java IOUtils.copy怎麽用?Java IOUtils.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.util.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: download
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static void download(String from, String to) {
InputStream in = null;
OutputStream out = null;
try {
URL apdf = new URL(from);
in = apdf.openStream();
System.out.println("開始下載:" + from);
out = new FileOutputStream(new File(to));
IOUtils.copy(in, out);
out.flush();
System.out.println("下載完成:" + to);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
示例2: decompress
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Decompresses the whole of the compressed RTF
* stream, outputting the resulting RTF bytes.
* Note - will decompress any padding at the end of
* the input, if present, use {@link #getDeCompressedSize()}
* if you need to know how much of the result is
* real. (Padding may be up to 7 bytes).
*/
public void decompress(InputStream src, OutputStream res) throws IOException {
// Validate the header on the front of the RTF
compressedSize = LittleEndian.readInt(src);
decompressedSize = LittleEndian.readInt(src);
int compressionType = LittleEndian.readInt(src);
int dataCRC = LittleEndian.readInt(src);
// TODO - Handle CRC checking on the output side
// Do we need to do anything?
if(compressionType == UNCOMPRESSED_SIGNATURE_INT) {
// Nope, nothing fancy to do
IOUtils.copy(src, res);
} else if(compressionType == COMPRESSED_SIGNATURE_INT) {
// We need to decompress it below
} else {
throw new IllegalArgumentException("Invalid compression signature " + compressionType);
}
// Have it processed
super.decompress(src, res);
}
示例3: copyToTempFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
String partName = packagePart.getPartName().getName();
partName = partName.substring(partName.lastIndexOf('/')+1);
final int idx = partName.lastIndexOf('.');
final String prefix = ((idx == -1) ? partName : partName.substring(0, idx)) + "-";
final String suffix = (idx == -1 || idx == partName.length()-1) ? "" : partName.substring(idx);
final File of = TempFile.createTempFile(prefix, suffix);
try (FileOutputStream fos = new FileOutputStream(of)) {
IOUtils.copy(is, fos);
}
of.deleteOnExit();
return of;
}
示例4: copyToTempFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
final String partName = entry.getName();
final int idx = partName.lastIndexOf('.');
final String prefix = ((idx == -1) ? partName : partName.substring(0, idx)) + "-";
final String suffix = (idx == -1 || idx == partName.length()-1) ? "" : partName.substring(idx);
final File of = TempFile.createTempFile(prefix, suffix);
try (FileOutputStream fos = new FileOutputStream(of)) {
IOUtils.copy(is, fos);
}
of.deleteOnExit();
return of;
}
示例5: copyToTempFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
final String prefix = "embed-"+embed.getPersistId()+"-";
final String suffix = ".dat";
final File of = TempFile.createTempFile(prefix, suffix);
try (FileOutputStream fos = new FileOutputStream(of)) {
IOUtils.copy(is, fos);
}
of.deleteOnExit();
return of;
}
示例6: copyToTempFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
final String prefix = record.getClass().getSimpleName() + "-";
final String suffix = ".zip";
final File of = TempFile.createTempFile(prefix, suffix);
try (FileOutputStream fos = new FileOutputStream(of)) {
IOUtils.copy(is, fos);
}
of.deleteOnExit();
return of;
}
示例7: copy
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private void copy(final InputStream input, OutputStream output, long start, long length) throws InterruptedStreamException {
// Slice the input stream considering offset and length
try (InputStream in = input) {
if (length > 0) {
long skip = in.skip(start);
if (skip != start) {
LOGGER.log(Level.WARNING, "Could not skip requested bytes (skipped: " + skip + " on " + start + ")");
}
byte[] data = new byte[1024 * 8];
long remaining = length;
int nr;
while (remaining > 0) {
nr = in.read(data);
if (nr < 0) {
break;
}
remaining -= nr;
output.write(data, 0, nr);
}
} else {
IOUtils.copy(in, output);
}
} catch (IOException e) {
// may be caused by a client side cancel
LOGGER.log(Level.FINE, "A downloading stream was interrupted.", e);
throw new InterruptedStreamException();
}
}
示例8: loadLibWin
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private static void loadLibWin(String path, String name) {
name = name + ".dll";
try {
// have to use a stream
InputStream in = InfrequentBehaviourFilter.class.getResourceAsStream("/" + name);
// always write to different location
File fileOut = new File(name);
OutputStream out = FileUtils.openOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
} catch (Exception e) {
throw new RuntimeException("Failed to load required DLL", e);
}
}
示例9: loadLibMac
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private static void loadLibMac(String path, String name) {
name = name + ".jnilib";
try {
// have to use a stream
InputStream in = InfrequentBehaviourFilter.class.getResourceAsStream("/" + name);
// always write to different location
File fileOut = new File(name);
OutputStream out = FileUtils.openOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
} catch (Exception e) {
throw new RuntimeException("Failed to load required JNILIB", e);
}
}
示例10: loadLibLinux
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private static void loadLibLinux(String path, String name) {
name = name + ".so";
try {
// have to use a stream
InputStream in = InfrequentBehaviourFilter.class.getResourceAsStream("/" + name);
// always write to different location
File fileOut = new File(name);
OutputStream out = FileUtils.openOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
} catch (Exception e) {
throw new RuntimeException("Failed to load required SO", e);
}
}
示例11: printGeneratedDRL
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Converts a decision table into DRL and prints the result in the
* passed OutputStream.
*
* @param decisionTable the decision table to be converted.
* @param target the stream where the generated DRL will be printed.
*/
private void printGeneratedDRL( InputStream decisionTable, OutputStream target ) {
try {
DecisionTableProviderImpl dtp = new DecisionTableProviderImpl();
String drl = dtp.loadFromInputStream( decisionTable, null );
IOUtils.copy( new ByteArrayInputStream( drl.getBytes() ), target );
} catch ( IOException ex ) {
throw new IllegalStateException( ex );
}
}
示例12: execute
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
@Override
public StreamingResponseBody execute(ExportParameters parameters) {
final TransformationCacheKey contentKey = getCacheKey(parameters);
ExportUtils.setExportHeaders(parameters.getExportName(), //
parameters.getArguments().get(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCODING), //
getFormat(parameters.getExportType()));
return outputStream -> {
try (InputStream cachedContent = contentCache.get(contentKey)) {
IOUtils.copy(cachedContent, outputStream);
}
};
}
示例13: toBlob
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public Blob toBlob(final String name, final File file) {
FileInputStream fis = null;
ByteArrayOutputStream baos = null;
try {
fis = new FileInputStream(file);
baos = new ByteArrayOutputStream();
IOUtils.copy(fis, baos);
return new Blob(name, ExcelService.XSLX_MIME_TYPE, baos.toByteArray());
} catch (IOException ex) {
throw new ExcelService.Exception(ex);
} finally {
IOUtils.closeQuietly(fis);
IOUtils.closeQuietly(baos);
}
}
示例14: copyFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private boolean copyFile( String src, String dest ) throws KettleFileException, IOException {
FileObject srcFile = getFileObjectFromKettleVFS( src );
FileObject destFile = getFileObjectFromKettleVFS( dest );
try ( InputStream in = KettleVFS.getInputStream( srcFile );
OutputStream out = KettleVFS.getOutputStream( destFile, false ) ) {
IOUtils.copy( in, out );
}
return true;
}
示例15: loadRamFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private FileObject loadRamFile( String filename ) throws Exception {
String targetUrl = RAMDIR + "/" + filename;
try ( InputStream source = getFileInputStream( filename ) ) {
FileObject fileObject = KettleVFS.getFileObject( targetUrl );
try ( OutputStream targetStream = fileObject.getContent().getOutputStream() ) {
IOUtils.copy( source, targetStream );
}
return fileObject;
}
}