public static byte[] readBytes(InputStream in) { if (in == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { pipe(in, baos); baos.close(); return baos.toByteArray(); } catch (IOException ex) { throw new IORuntimeException(ex); } }
protected boolean doProcessFile(HttpServletRequest request, HttpServletResponse response, PageRequest pageRequest, File file) throws ServletException, IOException { String mimeType = context_.getMimeType(pageRequest.getMy() .getLocalPathname()); if (mimeType != null) { response.setContentType(mimeType); } response.setDateHeader("Last-Modified", file.lastModified()); IOUtils.pipe(new FileInputStream(file), response.getOutputStream(), true, false); return true; }
byte[] getResourceBytes(String path) { InputStream is = null; try { is = jarURL.openStream(); JarInputStream jis = new JarInputStream(is); for (JarEntry entry = jis.getNextJarEntry(); entry != null; entry = jis.getNextJarEntry()) { String name = entry.getName(); if (name.equals(classesPath + path)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.pipe(jis, baos, false, false); return baos.toByteArray(); } else if (name.startsWith(libPath) && name.toLowerCase().endsWith(SUFFIX_JAR)) { JarInputStream jjis = new JarInputStream(jis); for (JarEntry e = jjis.getNextJarEntry(); e != null; e = jjis.getNextJarEntry()) { String n = e.getName(); if (n.equals(path)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.pipe(jjis, baos, false, false); return baos.toByteArray(); } } } } return null; } catch (IOException ex) { return null; } finally { IOUtils.closeQuietly(is); } }
if (name.equals(classesPath + path)) { File file = new File(tempDir, classesPath + PATH_DELIMITER + path); IOUtils.pipe(jis, new FileOutputStream(file), false, true); file.deleteOnExit(); urlList.add(file.toURI().toURL()); if (n.equals(path)) { File file = new File(tempDir, name + PATH_DELIMITER + path); IOUtils.pipe(jis, new FileOutputStream(file), false, true); file.deleteOnExit(); urlList.add(file.toURI().toURL());
if (name.equals(classesPath + path)) { File file = new File(tempDir, classesPath + PATH_DELIMITER + path); IOUtils.pipe(jis, new FileOutputStream(file), false, true); file.deleteOnExit(); return file.toURI().toURL(); if (n.equals(path)) { File file = new File(tempDir, name + PATH_DELIMITER + path); IOUtils.pipe(jis, new FileOutputStream(file), false, true); file.deleteOnExit(); return file.toURI().toURL();
public static void pipe(InputStream in, OutputStream out, boolean closeInputStream, boolean closeOutputStream) throws IOException { BufferedInputStream bis; if (in instanceof BufferedInputStream) { bis = (BufferedInputStream)in; } else { bis = new BufferedInputStream(in); } BufferedOutputStream bos; if (out instanceof BufferedOutputStream) { bos = (BufferedOutputStream)out; } else { bos = new BufferedOutputStream(out); } try { byte[] buf = new byte[BUF_SIZE]; int len; while ((len = bis.read(buf)) != -1) { bos.write(buf, 0, len); } bos.flush(); } finally { if (closeInputStream) { closeQuietly(bis); } if (closeOutputStream) { closeQuietly(bos); }
public void doProcess(HttpServletRequest request, HttpServletResponse response, RequestProcessorChain chain) throws ServletException, IOException { String path = ServletUtils.getPath(request); Content content = contentByPathMap_.get(path); if (content != null) { String contentType = content.getContentType(); if (contentType == null) { contentType = context_.getMimeType(path); } if (contentType != null) { response.setContentType(contentType); } response.setDateHeader("Last-Modified", content .getLastModifiedTime()); // responseのoutputStreamのクローズ処理はコンテナに任せるのが吉なので // 閉じないように指定している。 IOUtils.pipe(content.getInputStream(), response.getOutputStream(), true, false); return; } chain.doProcess(request, response); } }
IOUtils.pipe(attr.getStream(key).getInputStream(), stream.getOutputStream()); } catch (IOException ex) {
try { tempFile = File.createTempFile("kvasir", null); IOUtils.pipe(archive_.getInputStream(), new FileOutputStream( tempFile)); zipFile = new ZipFile(tempFile);
is = mold.getBodyInputStream(); os = resource.getOutputStream(); IOUtils.pipe(is, os); } catch (IOException ex) { throw new IORuntimeException(ex);