當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtils.closeQuietly方法代碼示例

本文整理匯總了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();
        }
    }
}
 
開發者ID:To-da,項目名稱:spring-boot-examples,代碼行數:32,代碼來源:PoiExcelWriter.java

示例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);
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:11,代碼來源:POITopMenuBar.java

示例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);
}
 
開發者ID:rushingpig,項目名稱:poix,代碼行數:15,代碼來源:ImportBaseService.java

示例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);
    }
}
 
開發者ID:rushingpig,項目名稱:poix,代碼行數:44,代碼來源:ExcelImportServer.java

示例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);
    }
}
 
開發者ID:rushingpig,項目名稱:poix,代碼行數:16,代碼來源:ImageCache.java

示例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);
	}
}
 
開發者ID:wte4j,項目名稱:wte4j,代碼行數:20,代碼來源:Docx4JWordTemplate.java

示例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);
	}
}
 
開發者ID:niuxuetao,項目名稱:paxml,代碼行數:14,代碼來源:LineBasedFile.java

示例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;
}
 
開發者ID:niuxuetao,項目名稱:paxml,代碼行數:14,代碼來源:LineBasedFile.java

示例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);
    }
}
 
開發者ID:isisaddons-legacy,項目名稱:isis-module-excel,代碼行數:16,代碼來源:ExcelFileBlobConverter.java

示例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 );
    }
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:13,代碼來源:AbstractWordUtils.java

示例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 );
    }
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:13,代碼來源:HWPFLister.java

示例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 );
    }
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:13,代碼來源:AbstractExcelUtils.java

示例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);
    }
}
 
開發者ID:uq-eresearch,項目名稱:aorra,代碼行數:12,代碼來源:BackgroundImageCssStyle.java

示例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);
    }
}
 
開發者ID:uq-eresearch,項目名稱:aorra,代碼行數:15,代碼來源:FontManager.java

示例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);
	}
}
 
開發者ID:jaeksoft,項目名稱:opensearchserver,代碼行數:14,代碼來源:PropertiesUtils.java


注:本文中的org.apache.poi.util.IOUtils.closeQuietly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。