本文整理汇总了Java中org.apache.tomcat.util.http.fileupload.IOUtils类的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IOUtils类属于org.apache.tomcat.util.http.fileupload包,在下文中一共展示了IOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doDownload
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
/**
* 通过httpClient get 下载文件
*
* @param url 网络文件全路径
* @param savePath 保存文件全路径
* @return 状态码 200表示成功
*/
public static int doDownload(String url, String savePath) {
// 创建默认的HttpClient实例.
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
HttpGet get = new HttpGet(url);
CloseableHttpResponse closeableHttpResponse = null;
try {
closeableHttpResponse = closeableHttpClient.execute(get);
HttpEntity entity = closeableHttpResponse.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
FileOutputStream out = new FileOutputStream(savePath);
IOUtils.copy(in, out);
EntityUtils.consume(entity);
closeableHttpResponse.close();
}
int code = closeableHttpResponse.getStatusLine().getStatusCode();
closeableHttpClient.close();
return code;
} catch (IOException e) {
e.printStackTrace();
} finally {
closeSource(closeableHttpClient, closeableHttpResponse);
}
return 0;
}
示例2: 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);
}
示例3: 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);
}
}
}
示例4: fetchFavicons
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
private static List<Image> fetchFavicons() {
List<Image> favicons = new ArrayList<Image>(FAVICON_RESOURCE_SUFFIXES.length);
ByteArrayOutputStream faviconOut = new ByteArrayOutputStream();
for (String faviconSuffix : FAVICON_RESOURCE_SUFFIXES) {
try {
faviconOut.reset();
InputStream resourceIn = WebzLauncherGUI.class.getResourceAsStream(FAVICON_RESOURCE_PREFIX + faviconSuffix);
if (resourceIn != null) {
IOUtils.copy(resourceIn, faviconOut);
favicons.add(new ImageIcon(faviconOut.toByteArray()).getImage());
}
} catch (IOException e) {
// it's just a favicon - ignore
}
}
return favicons;
}
示例5: graphs
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
@RequestMapping(value = { "/graph **", "/graph **/**" })
public void graphs(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("image/png");
String path = (String) request
.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
stataService.saveCmd(path);
path = path.substring(7);
stataService.run("graph display " + path);
File f = stataService.graph(path);
InputStream in = new FileInputStream(f);
IOUtils.copy(in, response.getOutputStream());
}
示例6: 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;
}
示例7: readObject
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
/**
* Reads the state of this object during deserialization.
*
* @param in The stream from which the state should be read.
*
* @throws IOException if an error occurs.
* @throws ClassNotFoundException if class cannot be found.
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// read values
in.defaultReadObject();
OutputStream output = getOutputStream();
if (cachedContent != null) {
output.write(cachedContent);
} else {
FileInputStream input = new FileInputStream(dfosFile);
IOUtils.copy(input, output);
dfosFile.delete();
dfosFile = null;
}
output.close();
cachedContent = null;
}
示例8: testSaveAsDocx
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
@Test
public void testSaveAsDocx() throws FileNotFoundException, IOException{
File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.doc");
File outputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.docx");
IOUtils.copy(new FileInputStream(inputFile), new FileOutputStream(outputFile));
}
示例9: 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);
}
}
}
示例10: getMandateFile
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
@ApiOperation(value = "Get mandate file")
@RequestMapping(method = GET, value = "/{id}/file")
public void getMandateFile(@PathVariable("id") Long mandateId,
@ApiIgnore @AuthenticationPrincipal AuthenticatedPerson authenticatedPerson,
HttpServletResponse response) throws IOException {
Mandate mandate = getMandateOrThrow(mandateId, authenticatedPerson.getUserId());
response.addHeader("Content-Disposition", "attachment; filename=Tuleva_avaldus.bdoc");
byte[] content = mandate.getMandate().orElseThrow(() -> new RuntimeException("Mandate is not signed"));
IOUtils.copy(new ByteArrayInputStream(content), response.getOutputStream());
response.flushBuffer();
}
示例11: 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);
}
}
}
示例12: 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);
}
}
示例13: cacheInputStream
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
private void cacheInputStream() throws IOException {
/* Cache the inputstream in order to read it multiple times. For
* convenience, I use apache.commons IOUtils
*/
cachedBytes = new ByteArrayOutputStream();
IOUtils.copy(super.getInputStream(), cachedBytes);
}
示例14: graph
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
@RequestMapping("/graph")
public void graph(HttpServletResponse response) throws IOException {
response.setContentType("image/png");
stataService.saveCmd("/graph");
File f = stataService.graph();
InputStream in = new FileInputStream(f);
IOUtils.copy(in, response.getOutputStream());
}
示例15: est
import org.apache.tomcat.util.http.fileupload.IOUtils; //导入依赖的package包/类
@RequestMapping("/est")
public void est(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html");
String path = (String) request
.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
stataService.saveCmd(path);
File f = stataService.est();
InputStream in = new FileInputStream(f);
IOUtils.copy(in, response.getOutputStream());
}