本文整理匯總了Java中org.apache.poi.util.IOUtils.closeQuietly方法的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils.closeQuietly方法的具體用法?Java IOUtils.closeQuietly怎麽用?Java IOUtils.closeQuietly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.util.IOUtils
的用法示例。
在下文中一共展示了IOUtils.closeQuietly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* could be interesting for spring batch
*
* @param inputResource source of the data read by lines
* @param outputResource generated .xlsx resource
*/
public void process(Resource inputResource, Resource outputResource) {
SXSSFWorkbook wb = new SXSSFWorkbook(flushSize);
try {
wb.setCompressTempFiles(true); // temp files will be gzipped
final Sheet sh = wb.createSheet();
InputStreamReader is = new InputStreamReader(inputResource.getInputStream());
BufferedReader br = new BufferedReader(is);
final CreationHelper createHelper = sh.getWorkbook().getCreationHelper();
br.lines().forEachOrdered(string -> createRow(string, sh, createHelper));
FileOutputStream out = new FileOutputStream(outputResource.getFile());
wb.write(out);
IOUtils.closeQuietly(out);
} catch (IOException e) {
logger.error("IOE", e);
} finally {
if (wb != null) {
// dispose of temporary files backing this workbook on disk
wb.dispose();
}
}
}
示例2: clearCurrentFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void clearCurrentFile() {
Object userObject = treeRoot.getUserObject();
if (userObject instanceof TreeModelEntry) {
IOUtils.closeQuietly((TreeModelEntry)userObject);
treeRoot.setUserObject(null);
}
treeRoot.removeAllChildren();
treeRoot.setUserObject("Not loaded ...");
treeModel.reload(treeRoot);
}
示例3: saveThisExcel
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void saveThisExcel(ImportParams params, Class<?> pojoClass, boolean isXSSFWorkbook,
Workbook book) throws Exception {
String path = PoiPublicUtil.getWebRootPath(getSaveExcelUrl(params, pojoClass));
File savefile = new File(path);
if (!savefile.exists()) {
savefile.mkdirs();
}
SimpleDateFormat format = new SimpleDateFormat("yyyMMddHHmmss");
FileOutputStream fos = new FileOutputStream(
path + "/" + format.format(new Date()) + "_" + Math.round(Math.random() * 100000)
+ (isXSSFWorkbook == true ? ".xlsx" : ".xls"));
book.write(fos);
IOUtils.closeQuietly(fos);
}
示例4: saveImage
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
*
* @param object
* @param picId
* @param excelParams
* @param titleString
* @param pictures
* @param params
* @throws Exception
*/
private void saveImage(Object object, String picId, Map<String, ExcelImportEntity> excelParams,
String titleString, Map<String, PictureData> pictures,
ImportParams params) throws Exception {
if (pictures == null) {
return;
}
PictureData image = pictures.get(picId);
if(image == null) {
return;
}
byte[] data = image.getData();
String fileName = "pic" + Math.round(Math.random() * 100000000000L);
fileName += "." + PoiPublicUtil.getFileExtendName(data);
if (excelParams.get(titleString).getSaveType() == 1) {
String path = PoiPublicUtil
.getWebRootPath(getSaveUrl(excelParams.get(titleString), object));
File savefile = new File(path);
if (!savefile.exists()) {
savefile.mkdirs();
}
savefile = new File(path + "/" + fileName);
FileOutputStream fos = new FileOutputStream(savefile);
try {
fos.write(data);
} finally {
IOUtils.closeQuietly(fos);
}
setValues(excelParams.get(titleString), object,
getSaveUrl(excelParams.get(titleString), object) + "/" + fileName);
} else {
setValues(excelParams.get(titleString), object, data);
}
}
示例5: load
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
@Override
public byte[] load(String imagePath) throws Exception {
InputStream is = POICacheManager.getFile(imagePath);
BufferedImage bufferImg = ImageIO.read(is);
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
try {
ImageIO.write(bufferImg,
imagePath.substring(imagePath.indexOf(".") + 1, imagePath.length()),
byteArrayOut);
return byteArrayOut.toByteArray();
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(byteArrayOut);
}
}
示例6: writeAsOPCXml
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Writes this document as word xml to a OutputStream and closed the stream
* in any case.
*
* @param out
* - the Outputstream to write the document.
* @throws IOException
*/
public void writeAsOPCXml(OutputStream out) throws IOException {
try {
SaveToZipFile saveToZipFile = new SaveToZipFile(wordMLPackage);
saveToZipFile.saveFlatOPC(out);
} catch (Docx4JException e) {
unwrapIOException(e);
throw new WteException("Can not marshall document", e);
} finally {
IOUtils.closeQuietly(out);
}
}
示例7: LineBasedFile
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public LineBasedFile(Resource file, String encoding) {
name = PaxmlUtils.getResourceFile(file);
InputStream in = null;
try {
in = file.getInputStream();
reader = new BufferedReader(new InputStreamReader(in, encoding == null ? "UTF-8" : encoding));
// cache the 1st line
line = reader.readLine();
} catch (IOException e) {
IOUtils.closeQuietly(in);
throw new PaxmlRuntimeException("Cannot read file: " + name, e);
}
}
示例8: next
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
@Override
public String next() {
String result = line;
try {
// advance the cached line
line = reader.readLine();
} catch (IOException e) {
line = null;
IOUtils.closeQuietly(reader);
throw new PaxmlRuntimeException("Cannot read file: " + name, e);
}
return result;
}
示例9: 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);
}
}
示例10: loadDoc
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static HWPFDocumentCore loadDoc( File docFile ) throws IOException
{
final FileInputStream istream = new FileInputStream( docFile );
try
{
return loadDoc( istream );
}
finally
{
IOUtils.closeQuietly( istream );
}
}
示例11: loadDoc
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private static HWPFDocumentCore loadDoc( File docFile ) throws IOException
{
final FileInputStream istream = new FileInputStream( docFile );
try
{
return loadDoc( istream );
}
finally
{
IOUtils.closeQuietly( istream );
}
}
示例12: loadXls
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static HSSFWorkbook loadXls( File xlsFile ) throws IOException
{
final FileInputStream inputStream = new FileInputStream( xlsFile );
try
{
return new HSSFWorkbook( inputStream );
}
finally
{
IOUtils.closeQuietly( inputStream );
}
}
示例13: makeImageImageRenderer
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private ImageRenderer makeImageImageRenderer(String source) {
InputStream stream = null;
try {
stream = getResolver().resolve(source);
return new BufferedImageImageRenderer(ImageIO.read(stream));
} catch(Exception e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
}
示例14: registerFont
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void registerFont(String family, String src) {
try {
InputStream stream = resolver.resolve(src);
if(stream == null) {
throw new Exception("failed to resolve "+src);
}
Font font = Font.createFont(Font.TRUETYPE_FONT, stream);
fonts.put(family, font);
IOUtils.closeQuietly(stream);
} catch(Exception e) {
throw new RuntimeException(String.format(
"failed to register font %s with source %s", family, src), e);
}
}
示例15: loadFromXml
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static void loadFromXml(File propFile, Properties properties)
throws InvalidPropertiesFormatException, IOException {
if (!propFile.exists())
return;
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(propFile);
properties.loadFromXML(inputStream);
} finally {
if (inputStream != null)
IOUtils.closeQuietly(inputStream);
}
}