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();
}
}
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;
}
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);
}
}
}
}
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;
}
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);
}
}
Aggregations