List of usage examples for org.apache.commons.io IOUtils copy
public static void copy(Reader input, OutputStream output, String encoding) throws IOException
Reader
to bytes on an OutputStream
using the specified character encoding, and calling flush. From source file:net.fizzl.redditengine.data.ListMapValue.java
public static List<String> fromInputStream(InputStream is, String name) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromInputStream(writer.toString(), name); }
From source file:net.fizzl.redditengine.data.LinkListing.java
public static LinkListing fromInputStream(InputStream is) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromString(writer.toString()); }
From source file:com.joliciel.jochre.search.webClient.SearchWebClientUtils.java
public static String getJson(URL url) { try {/* ww w . j a va 2 s . c o m*/ URLConnection con = url.openConnection(); InputStream in = con.getInputStream(); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String json = writer.toString(); return json; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:net.fizzl.redditengine.data.GsonTemplate.java
/** * Returns an instance of class T from {@link InputStream} that contains JSON data * //from www. j a va 2 s. c om * @param is JSON as InputStream * @param type {@link Class}<T> for conversion from JSON to POJO * @return POJO representation of the JSON data * @throws IOException * @see Gson */ public static <T> T fromInputStream(InputStream is, Class<T> type) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromString(writer.toString(), type); }
From source file:net.fizzl.redditengine.data.SubredditListing.java
/** * Returns a {@link #SubredditListing} from an InputStream * /*from ww w. j a v a 2 s .c o m*/ * @param is InputStream containing a subreddit listing as JSON * @return SubredditListing * @throws IOException */ public static SubredditListing fromInputStream(InputStream is) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromString(writer.toString()); }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.ExperimentStarter.java
/** * Method which executes Groovy script provided in the pathToScript. * /*from w ww. ja v a 2 s . c o m*/ * @param pathToScript * path to Groovy script. */ public static void start(String pathToScript) throws InstantiationException, IllegalAccessException, IOException { ClassLoader parent = ExperimentStarter.class.getClassLoader(); GroovyClassLoader loader = new GroovyClassLoader(parent); StringWriter writer = new StringWriter(); IOUtils.copy(parent.getResourceAsStream(pathToScript), writer, "UTF-8"); Class<?> groovyClass = loader.parseClass(writer.toString()); GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance(); Object[] a = {}; groovyObject.invokeMethod("run", a); loader.close(); }
From source file:com.cloudmine.api.rest.response.ResponseBase.java
public static String readMessageBody(HttpResponse response) { InputStream jsonStream = null; StringWriter writer = new StringWriter(); try {//from w w w . j ava2 s.com jsonStream = response.getEntity().getContent(); IOUtils.copy(jsonStream, writer, JsonUtilities.ENCODING); } catch (IOException e) { LOG.error("Exception thrown", e); } return writer.toString(); }
From source file:lohbihler.process.ProcessRunner.java
private static String toString(final InputStream in) throws IOException { final StringWriter output = new StringWriter(); IOUtils.copy(in, output, ASCII); return output.toString(); }
From source file:net.fizzl.redditengine.data.CommentListing.java
/** * Returns a {@link #CommentListing} from an InputStream * /*w w w . j a v a2 s .co m*/ * @param is InputStream containing a comment listing as JSON * @return CommentListing * @throws IOException * @throws JSONException */ public static CommentListing fromInputStream(InputStream is) throws IOException, JSONException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromString(writer.toString()); }
From source file:it.cnr.ilc.tokenizer.utils.InputToString.java
/** * Convert an inputstream into a string// w w w .ja va 2 s . c o m * @param theUrl the url to get the context from * @return the string from the input */ public static String convertInputStreamFromUrlToString(String theUrl) { StringWriter writer = new StringWriter(); InputStream is = null; String encoding = "UTF-8"; String message = ""; String theString = ""; try { is = new URL(theUrl).openStream(); IOUtils.copy(is, writer, encoding); theString = writer.toString(); } catch (Exception e) { message = "IOException in coverting the stream into a string " + e.getMessage(); Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, message); } //System.err.println("DDDD " + theString); IOUtils.closeQuietly(is); IOUtils.closeQuietly(writer); return theString; }