本文整理汇总了Java中org.apache.commons.io.IOUtils.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.closeQuietly方法的具体用法?Java IOUtils.closeQuietly怎么用?Java IOUtils.closeQuietly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: docxToHtml
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* 把docx转成html
* @param docxFilePath
* @param htmlPath
* @throws Exception
*/
public static void docxToHtml(String docxFilePath, String htmlPath) throws Exception {
OutputStream output = null;
try {
//
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new File(docxFilePath));
WMLPACKAGE_BUILDER.configChineseFonts(wmlPackage).configSimSunFont(wmlPackage);
WMLPACKAGE_WRITER.writeToHtml(wmlPackage, htmlPath);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(output);
}
}
示例2: saveReportFile
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void saveReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String file=req.getParameter("file");
file=ReportUtils.decodeFileName(file);
String content=req.getParameter("content");
ReportProvider targetReportProvider=null;
for(ReportProvider provider:reportProviders){
if(file.startsWith(provider.getPrefix())){
targetReportProvider=provider;
break;
}
}
if(targetReportProvider==null){
throw new ReportDesignException("File ["+file+"] not found available report provider.");
}
targetReportProvider.saveReport(file, content);
InputStream inputStream=IOUtils.toInputStream(content,"utf-8");
ReportDefinition reportDef=reportParser.parse(inputStream, file);
reportRender.rebuildReportDefinition(reportDef);
CacheUtils.cacheReportDefinition(file, reportDef);
IOUtils.closeQuietly(inputStream);
}
示例3: unLockQueue
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void unLockQueue(String queueID) {
if (locked.get() == null) {
return;
}
if (locked.get().decrementAndGet() > 0) {
return;
}
Jedis jedis = jedisPool.getResource();
try {
jedis.del(makeRedisLockKey(queueID));
locked.remove();
} finally {
IOUtils.closeQuietly(jedis);
}
}
示例4: sendFavicon
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void sendFavicon(HttpServletResponse response) throws IOException
{
InputStream fis = null;
OutputStream out = null;
try
{
response.setContentType("image/x-icon");
fis = WebServlet.class.getResourceAsStream("/resources/icon.ico");
out = response.getOutputStream();
IOUtils.copy(fis, out);
}
finally
{
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(fis);
}
return;
}
示例5: write
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void write(final S item, final Local file) throws AccessDeniedException {
final String content = item.<NSDictionary>serialize(SerializerFactory.get()).toXMLPropertyList();
final OutputStream out = file.getOutputStream(false);
try {
IOUtils.write(content, out, Charset.forName("UTF-8"));
}
catch(IOException e) {
throw new AccessDeniedException(String.format("Cannot create file %s", file.getAbsolute()), e);
}
finally {
IOUtils.closeQuietly(out);
}
}
示例6: copyStreamToJar
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
protected void copyStreamToJar(InputStream zin, ZipOutputStream out, String currentName, long fileTime) throws IOException {
// Create new entry for zip file.
ZipEntry newEntry = new ZipEntry(currentName);
// Make sure there is date and time set.
if (fileTime != -1) {
newEntry.setTime(fileTime); // If found set it into output file.
}
out.putNextEntry(newEntry);
if (zin != null) {
IOUtils.copy(zin, out);
}
IOUtils.closeQuietly(zin);
}
示例7: tryExtractSparkLibZip
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static URL[] tryExtractSparkLibZip(String sparkLibZipPath, String extractTo) throws IOException {
java.util.zip.ZipFile zipFile = new ZipFile(sparkLibZipPath);
List<URL> urls = new ArrayList<>();
try {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(extractTo, entry.getName());
urls.add(entryDestination.toURI().toURL());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
InputStream in = zipFile.getInputStream(entry);
OutputStream out = new FileOutputStream(entryDestination);
IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
out.close();
}
}
} finally {
zipFile.close();
}
return urls.toArray(new URL[urls.size()]);
}
示例8: parseProcess
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static ProcessDefinition parseProcess(byte[] bytes,long processId,boolean parseChildren) throws Exception{
ByteArrayInputStream bin=new ByteArrayInputStream(bytes);
try{
SAXReader reader=new SAXReader();
Document document=reader.read(bin);
Element root=document.getRootElement();
if(processParser.support(root)){
ProcessDefinition pd=(ProcessDefinition)processParser.parse(root,processId,parseChildren);
return pd;
}
return null;
}finally{
IOUtils.closeQuietly(bin);
}
}
示例9: run
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void run() {
try {
IOUtils.copy(input, output);
} catch (IOException e) {
logger.error("", e);
} finally {
IOUtils.closeQuietly(output);
}
}
示例10: releaseBuffer
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public synchronized void releaseBuffer(ByteBuffer buffer) {
if (buffer == EMPTY_BUFFER) return;
Object val = getExtendedReadBuffers().remove(buffer);
if (val == null) {
throw new IllegalArgumentException("tried to release a buffer " +
"that was not created by this stream, " + buffer);
}
if (val instanceof ClientMmap) {
IOUtils.closeQuietly((ClientMmap)val);
} else if (val instanceof ByteBufferPool) {
((ByteBufferPool)val).putBuffer(buffer);
}
}
示例11: doReadDerby
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Derby does not allow to read from the blob after the connection has been closed.
* It also requires an outcome of commit/rollback.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream doReadDerby(String id) {
Handle h = dbi.open();
try {
h.getConnection().setAutoCommit(false);
List<Map<String, Object>> res = h.select("SELECT data FROM icon_filestore WHERE id=?", id);
Optional<Blob> blob = res.stream()
.map(row -> row.get("data"))
.map(Blob.class::cast)
.findFirst();
if (blob.isPresent()) {
return new HandleCloserInputStream(h, blob.get().getBinaryStream());
} else {
h.commit();
h.close();
return null;
}
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
// Do cleanup
try {
h.rollback();
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
// ignore
}
IOUtils.closeQuietly(h);
throw IconDataAccessException.launderThrowable(e);
}
}
示例12: closeResourcePack
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void closeResourcePack()
{
if (this.reResourcePack instanceof Closeable)
{
IOUtils.closeQuietly((Closeable)this.reResourcePack);
}
}
示例13: remove
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void remove(AbstractMetaStore metaStore) {
if (metaStore.getFederationType() == PRIMARY) {
primaryDatabaseMapping = null;
primaryDatabasesCache.invalidateAll();
} else {
for (String databaseName : ((FederatedMetaStore) metaStore).getMappedDatabases()) {
mappingsByDatabaseName.remove(databaseName.toLowerCase());
}
}
DatabaseMapping removed = mappingsByMetaStoreName.remove(metaStore.getName());
IOUtils.closeQuietly(removed);
}
示例14: extract
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public String extract(WordprocessingMLPackage wmlPackage) throws Exception {
StringBuilderWriter output = new StringBuilderWriter();
try {
this.extract(wmlPackage, output);
} finally {
IOUtils.closeQuietly(output);
}
return output.toString();
}
示例15: size
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public long size(String queueID) {
Jedis jedis = jedisPool.getResource();
try {
return jedis.hlen(makeDataKey(queueID));
} finally {
IOUtils.closeQuietly(jedis);
}
}