List of usage examples for java.io Writer write
public void write(String str, int off, int len) throws IOException
From source file:com.websqrd.catbot.scraping.HttpHandler.java
/** * ? ./*from ww w . ja v a 2s. co m*/ */ public static String executeGet2(HttpClient httpclient, String url, String encoding, String[] a) throws IOException { String type = "text"; HttpGet httget = new HttpGet(url); HttpResponse response = httpclient.execute(httget); HttpEntity entity = response.getEntity(); Header header = entity.getContentType(); if (header != null) { type = header.getValue().toLowerCase(); } //InputStream to String InputStream is = entity.getContent(); Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, encoding)); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } a[0] = writer.toString(); return type; }
From source file:cz.incad.kramerius.k5indexer.Commiter.java
/** * Pipes everything from the reader to the writer via a buffer *///from w w w .j av a 2s.co m private static void pipe(Reader reader, Writer writer) throws IOException { char[] buf = new char[1024]; int read = 0; while ((read = reader.read(buf)) >= 0) { writer.write(buf, 0, read); } writer.flush(); }
From source file:com.microsoft.tfs.jni.helpers.FileCopyHelper.java
private static void copy(final Reader source, final Writer destination) throws IOException { final char[] buffer = new char[4096]; int len;//from w w w . ja v a 2 s . com while ((len = source.read(buffer)) != -1) { destination.write(buffer, 0, len); } }
From source file:FileUtil.java
/** * Just copies all characters from <I>in</I> to <I>out</I>. The copying * is performed using a buffer of bytes. * * @since 1.5.8/*from w ww. j a v a2 s.com*/ * @param in The reader to copy from * @param out The reader to copy to * @throws IOException If reading or writing failed. */ public static void copyContents(Reader in, Writer out) throws IOException { char[] buf = new char[BUFFER_SIZE]; int bytesRead = 0; while ((bytesRead = in.read(buf)) > 0) { out.write(buf, 0, bytesRead); } out.flush(); }
From source file:Main.java
private static void __htmlTextToPlainText(String text, Writer writer) throws IOException { StringReader sr = new StringReader(text); char[] chunk = new char[1024 * 64]; while (true) { int charsRead = sr.read(chunk, 0, chunk.length); if (charsRead <= 0) break; int lastPos = 0; for (int i = 0; i < chunk.length; i++) { if (chunk[i] == '<') { writer.write(chunk, lastPos, i - lastPos); writer.write("<"); lastPos = i + 1;//from www . j ava 2 s. co m } else if (chunk[i] == '>') { writer.write(chunk, lastPos, i - lastPos); writer.write(">"); lastPos = i + 1; } } if (lastPos < chunk.length) { writer.write(chunk, lastPos, chunk.length - lastPos); } } }
From source file:FileCopyUtils.java
/** * Copy the contents of the given Reader to the given Writer. * Closes both when done./*www .ja v a 2s . c o m*/ * @param in the Reader to copy from * @param out the Writer to copy to * @return the number of characters copied * @throws IOException in case of I/O errors */ public static int copy(Reader in, Writer out) throws IOException { try { int byteCount = 0; char[] buffer = new char[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); byteCount += bytesRead; } out.flush(); return byteCount; } finally { try { in.close(); } catch (IOException ex) { System.out.println("Could not close Reader" + ex); } try { out.close(); } catch (IOException ex) { System.out.println("Could not close Writer:" + ex); } } }
From source file:com.grouptuity.venmo.VenmoUtility.java
public static String convertStreamToString(InputStream inputStream) throws IOException { if (inputStream != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try {/*from w w w . j av a2s . c o m*/ Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 1024); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { inputStream.close(); } return writer.toString(); } else return ""; }
From source file:CopyUtils.java
/** * Copy chars from a <code>Reader</code> to a <code>Writer</code>. * @param input the <code>Reader</code> to read from * @param output the <code>Writer</code> to write to * @return the number of characters copied * @throws IOException In case of an I/O problem *//* w ww .ja va2 s .co m*/ public static int copy(Reader input, Writer output) throws IOException { char[] buffer = new char[DEFAULT_BUFFER_SIZE]; int count = 0; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; }
From source file:voldemort.utils.VoldemortIOUtils.java
public static long copyLarge(Reader input, Writer output, long limit) throws IOException { char[] buffer = new char[DEFAULT_BUFFER_SIZE]; long count = 0; int n = 0;//from w ww.j a v a2 s . co m long remaining = limit; while (remaining > 0) { n = (remaining > DEFAULT_BUFFER_SIZE) ? input.read(buffer) : input.read(buffer, 0, (int) remaining); if (n == -1) { break; } output.write(buffer, 0, n); count += n; remaining -= n; } return count; }
From source file:org.apache.manifoldcf.authorities.authorities.jira.JiraSession.java
private static String convertToString(HttpResponse httpResponse) throws IOException { HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream is = entity.getContent(); try {/*from www .j a v a 2 s. c o m*/ char[] buffer = new char[65536]; Reader r = new InputStreamReader(is, getCharSet(entity)); Writer w = new StringWriter(); try { while (true) { int amt = r.read(buffer); if (amt == -1) break; w.write(buffer, 0, amt); } } finally { w.flush(); } return w.toString(); } finally { is.close(); } } return ""; }