/** Copy Reader to Writer out until EOF or exception. * @param in the read to read from (until EOF) * @param out the writer to write to * @throws IOException if unable to copy the streams */ public static void copy(Reader in, Writer out) throws IOException { copy(in,out,-1); }
@Override public void copyTo(File destination) throws IOException { if (isDirectory()) { IO.copyDir(getFile(),destination); } else { if (destination.exists()) throw new IllegalArgumentException(destination+" exists"); IO.copy(getFile(),destination); } }
/** Copy Stream in to Stream out until EOF or exception. * @param in the input stream to read from (until EOF) * @param out the output stream to write to * @throws IOException if unable to copy streams */ public static void copy(InputStream in, OutputStream out) throws IOException { copy(in,out,-1); }
/** Read input stream to string. * @param in the reader to read from (until EOF) * @return the String parsed from the reader * @throws IOException if unable to read the stream (or handle the charset) */ public static String toString(Reader in) throws IOException { StringWriter writer=new StringWriter(); copy(in,writer); return writer.toString(); }
public static void copyFile(File from,File to) throws IOException { try (InputStream in=new FileInputStream(from); OutputStream out=new FileOutputStream(to)) { copy(in,out); } }
public static byte[] readBytes(InputStream in) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); copy(in,bout); return bout.toByteArray(); }
/** Read input stream to string. * @param in the stream to read from (until EOF) * @param encoding the Charset to use (can be null to use default Charset) * @return the String parsed from the stream * @throws IOException if unable to read the stream (or handle the charset) */ public static String toString(InputStream in, Charset encoding) throws IOException { StringWriter writer=new StringWriter(); InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding); copy(reader,writer); return writer.toString(); }
/** * @param out the output stream to write to * @param start First byte to write * @param count Bytes to write or -1 for all of them. * @throws IOException if unable to copy the Resource to the output */ public void writeTo(OutputStream out,long start,long count) throws IOException { try (InputStream in = getInputStream()) { in.skip(start); if (count<0) IO.copy(in,out); else IO.copy(in,out,count); } }
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException { InputStreamReader input = new InputStreamReader(in,StandardCharsets.UTF_16); StringWriter buf = new StringWriter(8192); IO.copy(input,buf,maxLength); // TODO implement maxKeys decodeTo(buf.getBuffer().toString(),map,StandardCharsets.UTF_16); }
public static void copyDir(File from,File to) throws IOException { if (to.exists()) { if (!to.isDirectory()) throw new IllegalArgumentException(to.toString()); } else to.mkdirs(); File[] files = from.listFiles(); if (files!=null) { for (int i=0;i<files.length;i++) { String name = files[i].getName(); if (".".equals(name) || "..".equals(name)) continue; copy(files[i],new File(to,name)); } } }
private Path extractPackedFile(JarFileResource configResource) throws IOException { String uri = configResource.getURI().toASCIIString(); int colon = uri.lastIndexOf(":"); int bang_slash = uri.indexOf("!/"); if (colon < 0 || bang_slash < 0 || colon > bang_slash) throw new IllegalArgumentException("Not resolved JarFile resource: " + uri); String entry_path = uri.substring(colon + 2).replace("!/", "__").replace('/', '_').replace('.', '_'); Path tmpDirectory = Files.createTempDirectory("users_store"); tmpDirectory.toFile().deleteOnExit(); Path extractedPath = Paths.get(tmpDirectory.toString(), entry_path); Files.deleteIfExists(extractedPath); extractedPath.toFile().deleteOnExit(); IO.copy(configResource.getInputStream(), new FileOutputStream(extractedPath.toFile())); if (isHotReload()) { LOG.warn("Cannot hot reload from packed configuration: {}", configResource); setHotReload(false); } return extractedPath; }
IO.copy(jin,fout);
/** Copy Stream in to Stream out until EOF or exception. */ public static void copy(InputStream in, OutputStream out) throws IOException { copy(in,out,-1); }
/** Copy Stream in to Stream out until EOF or exception. */ public static void copy(InputStream in, OutputStream out) throws IOException { copy(in,out,-1); }
/** Read input stream to string. */ public static String toString(Reader in) throws IOException { StringWriter writer=new StringWriter(); copy(in,writer); return writer.toString(); }
public static void copyFile(File from,File to) throws IOException { try (InputStream in=new FileInputStream(from); OutputStream out=new FileOutputStream(to)) { copy(in,out); } }
public static void copyFile(File from,File to) throws IOException { FileInputStream in=new FileInputStream(from); FileOutputStream out=new FileOutputStream(to); copy(in,out); in.close(); out.close(); }
/** Read input stream to string. */ public static String toString(InputStream in,String encoding) throws IOException { StringWriter writer=new StringWriter(); InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding); copy(reader,writer); return writer.toString(); }
public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException { InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16); StringWriter buf = new StringWriter(8192); IO.copy(input,buf,maxLength); decodeTo(buf.getBuffer().toString(),map,StringUtil.__UTF16,maxKeys); }