List of usage examples for java.io Writer write
public void write(String str, int off, int len) throws IOException
From source file:com.teotigraphix.caustk.utils.RuntimeUtils.java
/** * Converts and {@link InputStream} to a String. * // ww w . j a va2s . c o m * @param is The {@link InputStream} to read into a String. * @return THe String read from the stream. * @throws IOException */ public static final String convertStreamToString(InputStream is) throws IOException { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } return writer.toString(); }
From source file:no.digipost.android.utilities.JSONUtilities.java
public static String getJsonStringFromInputStream(final InputStream inputStream) { String content = ""; if (inputStream != null) { Writer writer = new StringWriter(); int buffer_size = 1024; char[] buffer = new char[buffer_size]; try {// w ww. j a va 2 s . c o m Reader reader = new BufferedReader(new InputStreamReader(inputStream, ApiConstants.ENCODING), buffer_size); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } inputStream.close(); reader.close(); writer.close(); } catch (Exception e) { } content = writer.toString(); } return content; }
From source file:ca.simplegames.micro.utils.IO.java
/** * Copy the contents of the given Reader to the given Writer. * Closes both when done./*from w ww . j a va2 s.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; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); byteCount += bytesRead; } out.flush(); return byteCount; } finally { IO.close(out); IO.close(in); } }
From source file:mx.itesm.mexadl.metrics.util.Util.java
/** * Load the contents of a configuration file into a String. * /*from w w w.jav a 2s .c o m*/ * @param path * @return * @throws Exception */ public static String loadFileContent(final String path) throws Exception { String returnValue; InputStream inputStream; inputStream = Util.class.getClassLoader().getResourceAsStream(path); returnValue = null; if (inputStream != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { inputStream.close(); } returnValue = writer.toString(); } return returnValue; }
From source file:niclients.main.getni.java
/** * To convert the InputStream to String we use the * Reader.read(char[] buffer) method. We iterate until the * Reader return -1 which means there's no more data to * read. We use the StringWriter class to produce the string. * * @param is inputStream from where content to be converted is read * * @exception throws IOException/*from w ww.j a v a 2 s . c o m*/ * * @return converted stream string (null if stream is empty) */ public static String convertStreamToString(InputStream is) throws IOException { if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } return writer.toString(); } else { return ""; } }
From source file:com.aqnote.shared.cryptology.util.lang.StreamUtil.java
/** * ??, ?. ?./* w ww . j a va2 s . c o m*/ * * @param in ? * @param out ? * @param bufferSize ?() * @throws IOException */ public static void io(Reader in, Writer out, int bufferSize) throws IOException { if (bufferSize == -1) { bufferSize = DEFAULT_BUFFER_SIZE >> 1; } char[] buffer = new char[bufferSize]; int amount; while ((amount = in.read(buffer)) >= 0) { out.write(buffer, 0, amount); } }
From source file:org.crazydog.util.spring.FileCopyUtils.java
/** * Copy the contents of the given Reader to the given Writer. * Closes both when done.//from w ww . j a va2s . co 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 { org.springframework.util.Assert.notNull(in, "No Reader specified"); org.springframework.util.Assert.notNull(out, "No Writer specified"); 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) { } try { out.close(); } catch (IOException ex) { } } }
From source file:de.feanor.yeoldemensa.data.MensaFactory.java
private static String convertStreamToString(InputStream is) throws IOException { /*/*from w ww.j a v a 2 s . c om*/ * To convert the InputStream to String we use the Reader.read(char[] * buffer) method. We iterate until the Reader return -1 which means * there's no more data to read. We use the StringWriter class to * produce the string. */ if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } return writer.toString(); } return ""; }
From source file:org.cryptsecure.HttpStringRequest.java
/** * Convert the content of a HTTP response into a string. * /*from w ww. j av a2 s .co m*/ * @param response * the response * @return the content as string * @throws IOException * Signals that an I/O exception has occurred. */ private static String getContentAsString(HttpResponse response) throws IOException { String returnString = ""; HttpEntity httpEntity = response.getEntity(); InputStream inputStream = httpEntity.getContent(); InputStreamReader is = new InputStreamReader(inputStream, "ISO-8859-1"); // "UTF-8"); if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(is); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } returnString = writer.toString().replace("\n", ""); } return returnString; }
From source file:com.ebay.cloud.cms.metadata.dataloader.MetadataDataLoader.java
private static String convertStreamToString(InputStream is) throws IOException { if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try {/* ww w. j av a 2 s .c om*/ Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } return writer.toString(); } else { return ""; } }