use of java.io.InputStreamReader in project Rutgers-Course-Tracker by tevjef.
the class Utils method parseResource.
public static String parseResource(Context context, int resource) throws IOException {
InputStream is = context.getResources().openRawResource(resource);
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();
}
use of java.io.InputStreamReader in project playn by threerings.
the class AndroidAssets method getTextSync.
@Override
public String getTextSync(String path) throws Exception {
InputStream is = openAsset(path);
try {
StringBuilder fileData = new StringBuilder(1000);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
return fileData.toString();
} finally {
is.close();
}
}
use of java.io.InputStreamReader in project blueprints by tinkerpop.
the class RestHelper method convertStreamToString.
private static String convertStreamToString(final InputStream is) throws Exception {
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
final StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
return sb.toString();
}
use of java.io.InputStreamReader in project blueprints by tinkerpop.
the class RestHelper method post.
private static JSONObject post(final String uri, final String postData, final String contentType, final String accept, final boolean noResult) {
try {
final HttpURLConnection connection = createConnection(uri, contentType, accept);
connection.setDoOutput(true);
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
// post data with Content-Length automatically set
writer.write(postData);
writer.close();
if (noResult) {
new InputStreamReader(connection.getInputStream()).close();
return null;
} else {
return new JSONObject(new JSONTokener(convertStreamToString(connection.getInputStream())));
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of java.io.InputStreamReader in project blueprints by tinkerpop.
the class RestHelper method act.
private static void act(final String uri, final String verb, final String contentType, final String accept) {
try {
final HttpURLConnection connection = createConnection(uri, contentType, accept);
connection.setRequestMethod(verb);
new InputStreamReader(connection.getInputStream()).close();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations