Search in sources :

Example 6 with InputStreamReader

use of java.io.InputStreamReader in project camel by apache.

the class FlatpackDataFormat method unmarshal.

public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
    InputStreamReader reader = new InputStreamReader(stream, IOHelper.getCharsetName(exchange));
    try {
        Parser parser = createParser(exchange, reader);
        DataSet dataSet = parser.parse();
        return new DataSetList(dataSet);
    } finally {
        reader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataSet(net.sf.flatpack.DataSet) DataSetList(org.apache.camel.component.flatpack.DataSetList) Parser(net.sf.flatpack.Parser)

Example 7 with InputStreamReader

use of java.io.InputStreamReader in project camel by apache.

the class DefaultPropertiesResolver method loadPropertiesFromClasspath.

protected Properties loadPropertiesFromClasspath(CamelContext context, boolean ignoreMissingLocation, PropertiesLocation location) throws IOException {
    Properties answer = new Properties();
    String path = location.getPath();
    InputStream is = context.getClassResolver().loadResourceAsStream(path);
    Reader reader = null;
    if (is == null) {
        if (!ignoreMissingLocation && !location.isOptional()) {
            throw new FileNotFoundException("Properties file " + path + " not found in classpath");
        }
    } else {
        try {
            if (propertiesComponent.getEncoding() != null) {
                reader = new BufferedReader(new InputStreamReader(is, propertiesComponent.getEncoding()));
                answer.load(reader);
            } else {
                answer.load(is);
            }
        } finally {
            IOHelper.close(reader, is);
        }
    }
    return answer;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties)

Example 8 with InputStreamReader

use of java.io.InputStreamReader in project camel by apache.

the class AnnotationTypeConverterLoader method findPackages.

protected void findPackages(Set<String> packages, ClassLoader classLoader) throws IOException {
    Enumeration<URL> resources = classLoader.getResources(META_INF_SERVICES);
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        String path = url.getPath();
        if (!visitedURIs.contains(path)) {
            // remember we have visited this uri so we wont read it twice
            visitedURIs.add(path);
            LOG.debug("Loading file {} to retrieve list of packages, from url: {}", META_INF_SERVICES, url);
            BufferedReader reader = IOHelper.buffered(new InputStreamReader(url.openStream(), UTF8));
            try {
                while (true) {
                    String line = reader.readLine();
                    if (line == null) {
                        break;
                    }
                    line = line.trim();
                    if (line.startsWith("#") || line.length() == 0) {
                        continue;
                    }
                    tokenize(packages, line);
                }
            } finally {
                IOHelper.close(reader, null, LOG);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) URL(java.net.URL)

Example 9 with InputStreamReader

use of java.io.InputStreamReader in project antlrworks by antlr.

the class StatisticsReporter method submitStats.

protected boolean submitStats(String id, String type, String data) {
    if (id == null) {
        error = "cannot submit stat with a null id";
        return false;
    }
    StringBuilder param = new StringBuilder();
    param.append(URL_SEND_STATS);
    param.append("ID=");
    param.append(id);
    param.append("&type=");
    param.append(type);
    param.append("&data=");
    param.append(XJUtils.encodeToURL(data));
    URLConnection urc;
    URL url;
    BufferedReader br;
    boolean success = false;
    try {
        url = new URL(param.toString());
        urc = url.openConnection();
        br = new BufferedReader(new InputStreamReader(urc.getInputStream()));
        success = br.readLine().equalsIgnoreCase("OK");
        br.close();
    } catch (IOException e) {
        error = e.toString();
    }
    return success;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL)

Example 10 with InputStreamReader

use of java.io.InputStreamReader in project camel by apache.

the class IOHelper method loadText.

/**
     * Loads the entire stream into memory as a String and returns it.
     * <p/>
     * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line
     * terminator at the of the text.
     * <p/>
     * Warning, don't use for crazy big streams :)
     */
public static String loadText(InputStream in) throws IOException {
    StringBuilder builder = new StringBuilder();
    InputStreamReader isr = new InputStreamReader(in);
    try {
        BufferedReader reader = buffered(isr);
        while (true) {
            String line = reader.readLine();
            if (line != null) {
                builder.append(line);
                builder.append("\n");
            } else {
                break;
            }
        }
        return builder.toString();
    } finally {
        close(isr, in);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Aggregations

InputStreamReader (java.io.InputStreamReader)4181 BufferedReader (java.io.BufferedReader)2938 IOException (java.io.IOException)1843 InputStream (java.io.InputStream)1083 FileInputStream (java.io.FileInputStream)767 ArrayList (java.util.ArrayList)494 URL (java.net.URL)471 File (java.io.File)448 Reader (java.io.Reader)446 Test (org.junit.Test)336 HttpURLConnection (java.net.HttpURLConnection)253 ByteArrayInputStream (java.io.ByteArrayInputStream)231 OutputStreamWriter (java.io.OutputStreamWriter)218 FileNotFoundException (java.io.FileNotFoundException)210 HashMap (java.util.HashMap)171 Socket (java.net.Socket)170 OutputStream (java.io.OutputStream)150 URLConnection (java.net.URLConnection)148 StringWriter (java.io.StringWriter)135 Path (org.apache.hadoop.fs.Path)123