public static String collect(Reader r) throws IOException { StringWriter w = new StringWriter(); copy(r, w); return w.toString(); }
public static void copy(Reader r, OutputStream o, String charset) throws IOException { try { OutputStreamWriter osw = new OutputStreamWriter(o, charset); copy(r, osw); } finally { r.close(); } }
public static String collect(InputStream a, String encoding) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(a, out); return new String(out.toByteArray(), encoding); }
public static void copy(InputStream in, URL out, String method) throws IOException { URLConnection c = out.openConnection(); if (c instanceof HttpURLConnection && method != null) { HttpURLConnection http = (HttpURLConnection) c; http.setRequestMethod(method); } c.setDoOutput(true); copy(in, c.getOutputStream()); }
public static String collect(URL a, String encoding) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(a.openStream(), out); return new String(out.toByteArray(), encoding); }
public static OutputStream copy(Reader r, OutputStream out, Charset charset) throws IOException { Writer w = writer(out, charset); try { copy(r, w); return out; } finally { w.flush(); } }
public static byte[] read(URL url) throws IOException { URLConnection conn = url.openConnection(); conn.connect(); int length = conn.getContentLength(); if (length == -1) { return read(conn.getInputStream()); } return copy(conn.getInputStream(), new byte[length]); }
public T from(byte[] f) throws Exception { IO.copy(f, this); return digest(); } }
public T from(File f) throws Exception { IO.copy(f, this); return digest(); } public T from(byte[] f) throws Exception {
public T from(byte[] f) throws Exception { IO.copy(f, this); return digest(); } }
public static Path copy(InputStream in, Path path) throws IOException { try (FileChannel out = writeChannel(path)) { copy(in, out); } return path; }
private ByteBuffer getBuffer() throws Exception { if (buffer != null) { return buffer; } if (size == -1) { return buffer = ByteBuffer.wrap(IO.read(zip.getInputStream(entry))); } ByteBuffer bb = IO.copy(zip.getInputStream(entry), ByteBuffer.allocate((int) size)); bb.flip(); return buffer = bb; }
private ByteBuffer getBuffer() throws Exception { if (buffer != null) { return buffer; } InputStream in = open(); if (size == -1) { return buffer = ByteBuffer.wrap(IO.read(in)); } ByteBuffer bb = IO.copy(in, ByteBuffer.allocate(size)); bb.flip(); return buffer = bb; }
public void update(InputStream inputStream, String etag, long modified) throws Exception { IO.mkdirs(this.file.getParentFile()); IO.copy(inputStream, this.file); if (modified > 0) { this.file.setLastModified(modified); } update(etag); }
private void copyResource(File dir, String path, Resource resource) throws Exception { File to = IO.getBasedFile(dir, path); IO.mkdirs(to.getParentFile()); IO.copy(resource.openInputStream(), to); }
@Override public void created(Project p) throws IOException { Workspace workspace = p.getWorkspace(); File source = workspace.getFile("ant/project.xml"); File dest = p.getFile("build.xml"); if (source.isFile()) IO.copy(source, dest); else IO.store(DEFAULT, dest); }
public String _sha1(String args[]) throws Exception { Macro.verifyCommand(args, _sha1Help, new Pattern[] { null, null, Pattern.compile("base64|hex") }, 2, 3); Digester<SHA1> digester = SHA1.getDigester(); Resource r = dot.getResource(args[1]); if (r == null) throw new FileNotFoundException("From sha1, not found " + args[1]); IO.copy(r.openInputStream(), digester); return Base64.encodeBase64(digester.digest().digest()); }