本文整理了Java中org.apache.poi.util.IOUtils.copy()
方法的一些代码示例,展示了IOUtils.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copy()
方法的具体详情如下:
包路径:org.apache.poi.util.IOUtils
类名称:IOUtils
方法名:copy
[英]Copy the contents of the stream to a new file.
[中]将流的内容复制到新文件。
代码示例来源:origin: org.apache.poi/poi
void read(InputStream in) throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
out.close();
buf = out.toByteArray();
}
public String getContent() {
代码示例来源:origin: org.apache.poi/poi
private static byte[] tryToDecompress(InputStream is) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
IOUtils.copy(new RLEDecompressingInputStream(is), bos);
} catch (IllegalArgumentException | IOException | IllegalStateException e){
return null;
}
return bos.toByteArray();
}
}
代码示例来源:origin: org.apache.poi/poi
public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream instream = new ByteArrayInputStream(compressed, offset, length);
InputStream stream = new RLEDecompressingInputStream(instream);
IOUtils.copy(stream, out);
stream.close();
out.close();
return out.toByteArray();
}
}
代码示例来源:origin: org.apache.poi/poi
/**
* Copy the contents of the stream to a new file.
*
* @param srcStream The {@link InputStream} which provides the data
* @param destFile The file where the data should be stored
* @return the amount of bytes copied
*
* @throws IOException If the target directory does not exist and cannot be created
* or if copying the data fails.
*/
public static long copy(InputStream srcStream, File destFile) throws IOException {
File destDirectory = destFile.getParentFile();
if (!(destDirectory.exists() || destDirectory.mkdirs())) {
throw new RuntimeException("Can't create destination directory: "+destDirectory);
}
try (OutputStream destStream = new FileOutputStream(destFile)) {
return IOUtils.copy(srcStream, destStream);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public boolean load(InputStream ios) throws InvalidFormatException {
// Grab the data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copy(ios, baos);
} catch(IOException e) {
throw new InvalidFormatException(e.getMessage());
}
// Save it
data = baos.toByteArray();
// All done
return true;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public byte[] getObjectData() throws IOException {
InputStream is = getObjectPart().getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(is, bos);
is.close();
return bos.toByteArray();
}
代码示例来源:origin: org.apache.poi/poi
@Override
public EmbeddedData extract(DirectoryNode dn) throws IOException {
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream is = dn.createDocumentInputStream("CONTENTS")) {
IOUtils.copy(is, bos);
return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF);
}
}
代码示例来源:origin: org.apache.poi/poi
/**
* Peeks at the first N bytes of the stream. Returns those bytes, but
* with the stream unaffected. Requires a stream that supports mark/reset,
* or a PushbackInputStream. If the stream has >0 but <N bytes,
* remaining bytes will be zero.
* @throws EmptyFileException if the stream is empty
*/
public static byte[] peekFirstNBytes(InputStream stream, int limit) throws IOException, EmptyFileException {
stream.mark(limit);
ByteArrayOutputStream bos = new ByteArrayOutputStream(limit);
copy(new BoundedInputStream(stream, limit), bos);
int readBytes = bos.size();
if (readBytes == 0) {
throw new EmptyFileException();
}
if (readBytes < limit) {
bos.write(new byte[limit-readBytes]);
}
byte peekedBytes[] = bos.toByteArray();
if(stream instanceof PushbackInputStream) {
PushbackInputStream pin = (PushbackInputStream)stream;
pin.unread(peekedBytes, 0, readBytes);
} else {
stream.reset();
}
return peekedBytes;
}
代码示例来源:origin: org.apache.poi/poi
IOUtils.copy(is, bos);
byte[] compressed = bos.toByteArray();
byte[] decompressed = null;
代码示例来源:origin: org.apache.poi/poi
@Override
public void processPOIFSWriterEvent(POIFSWriterEvent event) {
try {
try (OutputStream os = event.getStream();
FileInputStream fis = new FileInputStream(fileOut)) {
// StreamSize (8 bytes): An unsigned integer that specifies the number of bytes used by data
// encrypted within the EncryptedData field, not including the size of the StreamSize field.
// Note that the actual size of the \EncryptedPackage stream (1) can be larger than this
// value, depending on the block size of the chosen encryption algorithm
byte buf[] = new byte[LittleEndianConsts.LONG_SIZE];
LittleEndian.putLong(buf, 0, pos);
os.write(buf);
IOUtils.copy(fis, os);
}
if (!fileOut.delete()) {
LOG.log(POILogger.ERROR, "Can't delete temporary encryption file: "+fileOut);
}
} catch (IOException e) {
throw new EncryptedDocumentException(e);
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
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;
}
代码示例来源:origin: org.apache.poi/poi
@Override
public void processPOIFSWriterEvent(POIFSWriterEvent event) {
try {
LittleEndianOutputStream leos = new LittleEndianOutputStream(event.getStream());
// StreamSize (8 bytes): An unsigned integer that specifies the number of bytes used by data
// encrypted within the EncryptedData field, not including the size of the StreamSize field.
// Note that the actual size of the \EncryptedPackage stream (1) can be larger than this
// value, depending on the block size of the chosen encryption algorithm
leos.writeLong(countBytes);
FileInputStream fis = new FileInputStream(fileOut);
try {
IOUtils.copy(fis, leos);
} finally {
fis.close();
}
if (!fileOut.delete()) {
logger.log(POILogger.ERROR, "Can't delete temporary encryption file: "+fileOut);
}
leos.close();
} catch (IOException e) {
throw new EncryptedDocumentException(e);
}
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Adds a picture to the workbook.
*
* @param is The sream to read image from
* @param format The format of the picture.
*
* @return the index to this picture (0 based), the added picture can be obtained from {@link #getAllPictures()} .
* @see Workbook#PICTURE_TYPE_EMF
* @see Workbook#PICTURE_TYPE_WMF
* @see Workbook#PICTURE_TYPE_PICT
* @see Workbook#PICTURE_TYPE_JPEG
* @see Workbook#PICTURE_TYPE_PNG
* @see Workbook#PICTURE_TYPE_DIB
* @see #getAllPictures()
*/
public int addPicture(InputStream is, int format) throws IOException {
int imageNumber = getAllPictures().size() + 1;
XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], this.xssfFactory, imageNumber, true).getDocumentPart();
try (OutputStream out = img.getPackagePart().getOutputStream()) {
IOUtils.copy(is, out);
}
pictures.add(img);
return imageNumber - 1;
}
代码示例来源:origin: org.apache.poi/poi
length = IOUtils.copy(bis, os);
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Import a package part into this sheet.
*/
void importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
PackagePart destPP = getPackagePart();
PackagePartName srcPPName = srcPafrt.getPartName();
OPCPackage pkg = destPP.getPackage();
if(pkg.containPart(srcPPName)){
// already exists
return;
}
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
PackagePart part = pkg.createPart(srcPPName, srcPafrt.getContentType());
try {
OutputStream out = part.getOutputStream();
InputStream is = srcPafrt.getInputStream();
IOUtils.copy(is, out);
is.close();
out.close();
} catch (IOException e){
throw new POIXMLException(e);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
};
CipherOutputStream cos = new CipherOutputStream(fos2, ciEnc);
IOUtils.copy(zis, cos);
cos.close();
fos2.close();
代码示例来源:origin: org.apache.poi/poi-ooxml
IOUtils.copy(part.getInputStream(), out);
out.close();
代码示例来源:origin: org.apache.poi/poi-ooxml
IOUtils.copy(is, zos);
代码示例来源:origin: org.apache.poi/poi-ooxml
IOUtils.copy(vbaProjectStream, outputStream);
} finally {
IOUtils.closeQuietly(outputStream);
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Recursively copy package parts to the destination package
*/
private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, PackagePart part_tgt) throws OpenXML4JException, IOException {
PackageRelationshipCollection rels = part.getRelationships();
if(rels != null) for (PackageRelationship rel : rels) {
PackagePart p;
if(rel.getTargetMode() == TargetMode.EXTERNAL){
part_tgt.addExternalRelationship(rel.getTargetURI().toString(), rel.getRelationshipType(), rel.getId());
//external relations don't have associated package parts
continue;
}
URI uri = rel.getTargetURI();
if(uri.getRawFragment() != null) {
part_tgt.addRelationship(uri, rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
continue;
}
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
p = pkg.getPart(relName);
part_tgt.addRelationship(p.getPartName(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
PackagePart dest;
if(!tgt.containPart(p.getPartName())){
dest = tgt.createPart(p.getPartName(), p.getContentType());
OutputStream out = dest.getOutputStream();
IOUtils.copy(p.getInputStream(), out);
out.close();
copy(pkg, p, tgt, dest);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!