void setBodyInputStream0(InputStream bodyInputStream) { IOUtils.closeQuietly(bodyInputStream_); bodyInputStream_ = bodyInputStream; }
protected String readResource(Class<?> testClass, String name) { String className = testClass.getName(); int dot = className.lastIndexOf('.'); if (dot >= 0) { className = className.substring(dot + 1); } return IOUtils.readString(getClass().getResourceAsStream( className + "_" + name), "UTF-8", false); }
} finally { if (closeInputStream) { closeQuietly(bis); closeQuietly(bos);
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); } }
public static void writeString(OutputStream os, String string, String encoding, boolean normalizeLineSeparator) { writeString(os, string, encoding, normalizeLineSeparator, true); }
public byte[] getBodyBytes() { return IOUtils.readBytes(getBodyInputStream()); }
public static void writeBytes(OutputStream out, byte[] bytes) { writeBytes(out, bytes, true); }
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; }
public static void writeString(Writer writer, String string, boolean normalizeLineSeparator) { writeString(writer, string, normalizeLineSeparator, true); }
@Override public byte[] getContent() { try { return IOUtils.readBytes(streamContent()); } catch (IOException ex) { throw new IORuntimeException("Can't get content: " + element_, ex); } } }
void commit(byte[] response) throws IOException { IOUtils.writeBytes(getResponse().getOutputStream(), response, false); } }
public static void writeBytes(OutputStream out, byte[] bytes, boolean close) { BufferedOutputStream bos; if (out instanceof BufferedOutputStream) { bos = (BufferedOutputStream)out; } else { bos = new BufferedOutputStream(out); } try { bos.write(bytes); bos.flush(); } catch (IOException ex) { throw new IORuntimeException(ex); } finally { if (close) { closeQuietly(out); } } } }
public String toHTML(InputStream in, String encoding, String type, VariableResolver resolver) { if (in == null) { return null; } if (encoding == null) { encoding = ENCODING_DEFAULT; } return engine_.evaluate(IOUtils.readString(in, encoding, false)); }
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); } }
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); } }
public static void writeString(OutputStream os, String string, String encoding, boolean normalizeLineSeparator, boolean close) { try { writeString(new OutputStreamWriter(os, encoding), string, normalizeLineSeparator, close); } catch (UnsupportedEncodingException ex) { throw new IORuntimeException(ex); } }
@Override protected void setContent(PageElement element, String encoding, InputStream in) throws NamingException { if (TYPE_ATTACHED.equals(element.getType())) { // inはnullのはずだが、念のため。 IOUtils.closeQuietly(in); } else { setPageContent(element, encoding, in); } } }
public String readText(String resourceName) { String resourcePath = getClass().getName().replace('.', '/') .concat("_").concat(resourceName); InputStream in = getClass().getClassLoader().getResourceAsStream( resourcePath); if (in == null) { throw new IORuntimeException("Specified resource does not exist: " + resourcePath); } return IOUtils.readString(in, "UTF-8", true); } }
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(); IOUtils.closeQuietly(is);
IOUtils.pipe(attr.getStream(key).getInputStream(), stream.getOutputStream()); } catch (IOException ex) {