本文整理汇总了Java中org.apache.tomcat.util.http.fileupload.IOUtils.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.closeQuietly方法的具体用法?Java IOUtils.closeQuietly怎么用?Java IOUtils.closeQuietly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.http.fileupload.IOUtils
的用法示例。
在下文中一共展示了IOUtils.closeQuietly方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateArclibXml
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**
* Generates ARCLib XML from the SIP package using SIP profile.
*
* @param sipPath path to the SIP package
* @param sipProfileId id of the SIP profile
* @param response response with the ARCLib XML
*
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws XPathExpressionException
* @throws TransformerException
*/
@RequestMapping(value = "/generate", method = RequestMethod.PUT)
public void generateArclibXml(
@RequestParam("sipPath") String sipPath, @RequestParam("sipProfileId") String sipProfileId, HttpServletResponse response)
throws ParserConfigurationException, IOException, SAXException, XPathExpressionException, TransformerException {
String xml = generator.generateArclibXml(sipPath, sipProfileId);
response.setContentType("application/xml");
response.setStatus(200);
response.addHeader("Content-Disposition", "attachment; sipPath=" + sipPath + "_sipProfileId_" + sipProfileId);
ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8.name()));
IOUtils.copyLarge(xmlInputStream, response.getOutputStream());
IOUtils.closeQuietly(xmlInputStream);
}
示例2: handlerAjax
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
private void handlerAjax(HttpServletResponse response, Exception ex) {
// 设置错误的响应状态码
response.setStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR);
PrintWriter writer = null;
if (ex instanceof GenericException) {
try {
writer = response.getWriter();
CustomResp customResp = CustomResp.withEx((GenericException) ex);
writer.write(JSON.toJSONString(customResp));
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(writer);
}
}
}
示例3: load
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
public static Properties load(String srcpath){
Properties config = new Properties();
try {
config = loadProperties(srcpath);
} catch (Exception e) {
InputStream in = null;
try {
in = TomcatConfig.class.getResourceAsStream(srcpath);
if(in==null)
throw new RuntimeException("can load resource as stream with : " +srcpath );
config.load(in);
} catch (Exception e1) {
throw new RuntimeException("load config error: " + srcpath, e);
} finally{
IOUtils.closeQuietly(in);
}
}
return config;
}
示例4: copy
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**
* Copies the contents of the given {@link InputStream}
* to the given {@link OutputStream}.
*
* @param inputStream The input stream, which is being read.
* It is guaranteed, that {@link InputStream#close()} is called
* on the stream.
* @param outputStream The output stream, to which data should
* be written. May be null, in which case the input streams
* contents are simply discarded.
* @param closeOutputStream True guarantees, that {@link OutputStream#close()}
* is called on the stream. False indicates, that only
* {@link OutputStream#flush()} should be called finally.
* @param buffer Temporary buffer, which is to be used for
* copying data.
* @return Number of bytes, which have been copied.
* @throws IOException An I/O error occurred.
*/
public static long copy(InputStream inputStream,
OutputStream outputStream, boolean closeOutputStream,
byte[] buffer)
throws IOException {
OutputStream out = outputStream;
InputStream in = inputStream;
try {
long total = 0;
for (;;) {
int res = in.read(buffer);
if (res == -1) {
break;
}
if (res > 0) {
total += res;
if (out != null) {
out.write(buffer, 0, res);
}
}
}
if (out != null) {
if (closeOutputStream) {
out.close();
} else {
out.flush();
}
out = null;
}
in.close();
in = null;
return total;
} finally {
IOUtils.closeQuietly(in);
if (closeOutputStream) {
IOUtils.closeQuietly(out);
}
}
}
示例5: copy
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**
* Copies the contents of the given {@link InputStream} to the given
* {@link OutputStream}.
*
* @param inputStream
* The input stream, which is being read. It is guaranteed, that
* {@link InputStream#close()} is called on the stream.
* @param outputStream
* The output stream, to which data should be written. May be
* null, in which case the input streams contents are simply
* discarded.
* @param closeOutputStream
* True guarantees, that {@link OutputStream#close()} is called
* on the stream. False indicates, that only
* {@link OutputStream#flush()} should be called finally.
* @param buffer
* Temporary buffer, which is to be used for copying data.
* @return Number of bytes, which have been copied.
* @throws IOException
* An I/O error occurred.
*/
public static long copy(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream,
byte[] buffer) throws IOException {
OutputStream out = outputStream;
InputStream in = inputStream;
try {
long total = 0;
for (;;) {
int res = in.read(buffer);
if (res == -1) {
break;
}
if (res > 0) {
total += res;
if (out != null) {
out.write(buffer, 0, res);
}
}
}
if (out != null) {
if (closeOutputStream) {
out.close();
} else {
out.flush();
}
out = null;
}
in.close();
in = null;
return total;
} finally {
IOUtils.closeQuietly(in);
if (closeOutputStream) {
IOUtils.closeQuietly(out);
}
}
}
示例6: getFileResource
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
private FileResource getFileResource(String path,String type){
InputStream inputStream = null;
try {
ClassPathResource resource = new ClassPathResource(path);
inputStream = resource.getInputStream();
File tempFile = File.createTempFile("ds_" + System.currentTimeMillis(), type);
FileUtils.copyInputStreamToFile(inputStream, tempFile);
return new FileResource(tempFile);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
IOUtils.closeQuietly(inputStream);
}
}
示例7: service
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**************************************************************************/
@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp)
throws ServletException, IOException
{
InputStream is = this.getClass().getResourceAsStream("examplerdf.rdf");
IOUtils.copy(is, rsp.getOutputStream());
IOUtils.closeQuietly(is);
}
示例8: exportZipByGroupId
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/api/sql/exportByGroupId", method = RequestMethod.GET, produces = "application/zip")
public byte[] exportZipByGroupId(
@RequestParam long groupid,
@RequestParam String filename,
HttpServletResponse response) throws Exception {
//setting headers
response.setContentType("application/zip");
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + ".zip\"");
//creating byteArray stream, make it bufforable and passing this buffor to ZipOutputStream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);
//simple file list, just for tests
List<File> files = prepareSqlFileByGroupId(groupid);
//packing files
for (File file : files) {
//new zip entry and copying inputstream with file to zipOutputStream, after all closing streams
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
FileInputStream fileInputStream = new FileInputStream(file);
IOUtils.copy(fileInputStream, zipOutputStream);
fileInputStream.close();
zipOutputStream.closeEntry();
}
if (zipOutputStream != null) {
zipOutputStream.finish();
zipOutputStream.flush();
IOUtils.closeQuietly(zipOutputStream);
}
IOUtils.closeQuietly(bufferedOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
housekeepCreateFile();
return byteArrayOutputStream.toByteArray();
}
示例9: exportZipByTargetVersion
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/api/sql/exportByTargetVersion", method = RequestMethod.GET, produces = "application/zip")
public byte[] exportZipByTargetVersion(
@RequestParam String targetVision,
@RequestParam String filename,
HttpServletResponse response) throws Exception {
//setting headers
response.setContentType("application/zip");
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + ".zip\"");
//creating byteArray stream, make it bufforable and passing this buffor to ZipOutputStream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);
List<SqlCIGroup> sqlCIGroupList = sqlCIGroupRepository.findByTargetVersion(targetVision);
//simple file list, just for tests
ArrayList<File> files = new ArrayList<File>();
Iterator itrSqlCIGroup = sqlCIGroupList.iterator();
while (itrSqlCIGroup.hasNext()) {
SqlCIGroup sqlCIGroup = (SqlCIGroup) itrSqlCIGroup.next();
files.addAll(prepareSqlFileByGroupId(sqlCIGroup.getId()));
}
//packing files
for (File file : files) {
//new zip entry and copying inputstream with file to zipOutputStream, after all closing streams
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
FileInputStream fileInputStream = new FileInputStream(file);
IOUtils.copy(fileInputStream, zipOutputStream);
fileInputStream.close();
zipOutputStream.closeEntry();
}
if (zipOutputStream != null) {
zipOutputStream.finish();
zipOutputStream.flush();
IOUtils.closeQuietly(zipOutputStream);
}
IOUtils.closeQuietly(bufferedOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
housekeepCreateFile();
return byteArrayOutputStream.toByteArray();
}