use of java.io.InputStreamReader in project cordova-android-chromeview by thedracle.
the class FileTransfer method createFileTransferError.
private static JSONObject createFileTransferError(int errorCode, String source, String target, URLConnection connection) {
int httpStatus = 0;
StringBuilder bodyBuilder = new StringBuilder();
String body = null;
if (connection != null) {
try {
if (connection instanceof HttpURLConnection) {
httpStatus = ((HttpURLConnection) connection).getResponseCode();
InputStream err = ((HttpURLConnection) connection).getErrorStream();
if (err != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(err, "UTF-8"));
String line = reader.readLine();
while (line != null) {
bodyBuilder.append(line);
line = reader.readLine();
if (line != null)
bodyBuilder.append('\n');
}
body = bodyBuilder.toString();
}
}
} catch (IOException e) {
Log.w(LOG_TAG, "Error getting HTTP status code from connection.", e);
}
}
return createFileTransferError(errorCode, source, target, body, httpStatus);
}
use of java.io.InputStreamReader in project bazel by bazelbuild.
the class JarFilter method parseSrcJars.
static List<String> parseSrcJars(List<Path> srcJars) throws IOException {
List<String> result = Lists.newArrayList();
for (Path srcJar : srcJars) {
try (ZipFile sourceZipFile = new ZipFile(srcJar.toFile())) {
Enumeration<? extends ZipEntry> entries = sourceZipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.getName().endsWith(".java")) {
continue;
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(sourceZipFile.getInputStream(entry), UTF_8))) {
String packageString = parseDeclaredPackage(reader);
if (packageString != null) {
String archiveFileNamePrefix = getArchiveFileNamePrefix(entry.getName(), packageString);
result.add(archiveFileNamePrefix);
}
}
}
}
}
return result;
}
use of java.io.InputStreamReader in project jvm-tools by aragozin.
the class JarBuilderTool method toLines.
private static Collection<String> toLines(InputStream is) throws IOException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
List<String> result = new ArrayList<String>();
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
result.add(line);
}
return result;
} finally {
try {
is.close();
} catch (Exception e) {
// ignore
}
}
}
use of java.io.InputStreamReader in project bazel by bazelbuild.
the class HttpConnectorTest method serverError_retriesConnect.
@Test
public void serverError_retriesConnect() throws Exception {
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
try (Socket socket = server.accept()) {
readHttpRequest(socket.getInputStream());
sendLines(socket, "HTTP/1.1 500 Incredible Catastrophe", "Date: Fri, 31 Dec 1999 23:59:59 GMT", "Connection: close", "Content-Type: text/plain", "Content-Length: 8", "", "nononono");
}
try (Socket socket = server.accept()) {
readHttpRequest(socket.getInputStream());
sendLines(socket, "HTTP/1.1 200 OK", "Date: Fri, 31 Dec 1999 23:59:59 GMT", "Connection: close", "Content-Type: text/plain", "Content-Length: 5", "", "hello");
}
return null;
}
});
try (Reader payload = new InputStreamReader(connector.connect(new URL(String.format("http://127.0.0.1:%d", server.getLocalPort())), ImmutableMap.<String, String>of()).getInputStream(), ISO_8859_1)) {
assertThat(CharStreams.toString(payload)).isEqualTo("hello");
assertThat(clock.currentTimeMillis()).isEqualTo(100L);
}
}
}
use of java.io.InputStreamReader in project bazel by bazelbuild.
the class SkylarkRepositoryContextTest method testOutputFile.
private void testOutputFile(Path path, String content) throws IOException {
assertThat(path.exists()).isTrue();
assertThat(CharStreams.toString(new InputStreamReader(path.getInputStream(), StandardCharsets.UTF_8))).isEqualTo(content);
}
Aggregations