private void initFromStream(InputStream in) throws IOException { String allText = FileUtils.getStreamAsString(in, "ASCII"); String[] lines = allText.split("\n"); initFromLines(lines, 3); }
private void initFromStream(InputStream in) throws IOException { String allText = FileUtils.getStreamAsString(in, "ASCII"); String[] lines = allText.split("\n"); initFromLines(lines, 3); }
/** * Read a file into a string, using the given encoding, and return that string. * * @param file * file * @param encoding * encoding * @throws IOException * IOException * @return stream as string(fis, encoding) * @deprecated use {@link org.apache.commons.io.FileUtils#readFileToString(File, String)} instead */ @Deprecated public static String getFileAsString(File file, String encoding) throws IOException { FileInputStream fis = new FileInputStream(file); try { return getStreamAsString(fis, encoding); } finally { fis.close(); } }
/** * Read a file into a string, using the given encoding, and return that string. * * @param file * file * @param encoding * encoding * @throws IOException * IOException * @return stream as string(fis, encoding) * @deprecated use {@link org.apache.commons.io.FileUtils#readFileToString(File, String)} instead */ @Deprecated public static String getFileAsString(File file, String encoding) throws IOException { FileInputStream fis = new FileInputStream(file); try { return getStreamAsString(fis, encoding); } finally { fis.close(); } }
@Before public void setUp() throws IOException { targetfeatures = FileUtils.getStreamAsString(FeatureUtilsTest.class.getResourceAsStream("helloworld.targetfeatures"), "UTF-8"); }
@Test public void validatingParseString() throws Exception { String docAsString = FileUtils.getStreamAsString(DomUtilsTest.class.getResourceAsStream("sample.maryxml"), "UTF-8"); DomUtils.parseDocument(docAsString, true); }
@Before public void setUp() throws IOException { targetfeatures = FileUtils.getStreamAsString(FeatureUtilsTest.class.getResourceAsStream("helloworld.targetfeatures"), "UTF-8"); }
@Test public void lineArrayConstructor() throws Exception { String[] lines = FileUtils.getStreamAsString(getClass().getResourceAsStream("pop001.lab"), "ASCII").split("\n"); Labels l = new Labels(lines); assertEquals(10, l.items.length); }
public void run() { try { InputStream inputStream; if (args.length == 0 || args[0].equals("-")) inputStream = System.in; else inputStream = new FileInputStream(args[0]); String input = FileUtils.getStreamAsString(inputStream, "UTF-8"); process(input, MaryProperties.getProperty("input.type", "TEXT"), MaryProperties.getProperty("output.type", "AUDIO"), MaryProperties.getProperty("locale", "en_US"), MaryProperties.getProperty("audio.type", "WAVE"), MaryProperties.getProperty("voice", null), MaryProperties.getProperty("style", null), MaryProperties.getProperty("effect", null), MaryProperties.getProperty("output.type.params", null), System.out); } catch (Exception e) { throw new RuntimeException(e); } } };
private String serverInfoRequest(URL url) throws IOException { HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setRequestMethod("GET"); http.connect(); if (http.getResponseCode() != HttpURLConnection.HTTP_OK) { String errorData = ""; try { errorData = FileUtils.getStreamAsString(http.getErrorStream(), "UTF-8"); } catch (Exception e) { } throw new IOException(http.getResponseCode() + ":" + http.getResponseMessage() + "\n" + errorData); } return FileUtils.getStreamAsString(http.getInputStream(), "UTF-8"); /* * The following is example code if we were to use HttpClient: HttpClient httpclient = new DefaultHttpClient(); * * HttpGet httpget = new HttpGet("http://www.google.com/"); * * System.out.println("executing request " + httpget.getURI()); * * // Create a response handler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody * = httpclient.execute(httpget, responseHandler); System.out.println(responseBody); */ }
private void copyWithVarSubstitution(String resourceName, File destination, StrSubstitutor... moreSubstitutors) throws IOException { String resource = marytts.util.io.FileUtils.getStreamAsString( getClass().getResourceAsStream("templates/" + resourceName), "UTF-8"); String resourceWithReplacements = substitutor.replace(resource); for (StrSubstitutor more : moreSubstitutors) { resourceWithReplacements = more.replace(resourceWithReplacements); } PrintWriter out = new PrintWriter(destination, "UTF-8"); out.print(resourceWithReplacements); out.close(); }
String error; try { error = FileUtils.getStreamAsString(conn.getErrorStream(), "UTF-8"); } catch (IOException errE) {