use of java.io.InputStreamReader in project jstorm by alibaba.
the class Utils method readAndLogStream.
public static void readAndLogStream(String prefix, InputStream in) {
try {
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = r.readLine()) != null) {
LOG.info("{}:{}", prefix, line);
}
} catch (IOException e) {
LOG.warn("Error whiel trying to log stream", e);
}
}
use of java.io.InputStreamReader in project core by s4.
the class AvroSchemaSupplementer method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("No schema filename specified");
System.exit(1);
}
String filename = args[0];
FileReader fr = null;
BufferedReader br = null;
InputStreamReader isr = null;
try {
if (filename == "-") {
isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
} else {
fr = new FileReader(filename);
br = new BufferedReader(fr);
}
String inputLine = "";
StringBuffer jsonBuffer = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
jsonBuffer.append(inputLine);
}
JSONObject jsonRecord = new JSONObject(jsonBuffer.toString());
JSONObject keyPathElementSchema = new JSONObject();
keyPathElementSchema.put("name", "KeyPathElement");
keyPathElementSchema.put("type", "record");
JSONArray fieldsArray = new JSONArray();
JSONObject fieldRecord = new JSONObject();
fieldRecord.put("name", "index");
JSONArray typeArray = new JSONArray("[\"int\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "keyName");
typeArray = new JSONArray("[\"string\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
keyPathElementSchema.put("fields", fieldsArray);
JSONObject keyInfoSchema = new JSONObject();
keyInfoSchema.put("name", "KeyInfo");
keyInfoSchema.put("type", "record");
fieldsArray = new JSONArray();
fieldRecord = new JSONObject();
fieldRecord.put("name", "keyPath");
typeArray = new JSONArray("[\"string\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "fullKeyPath");
typeArray = new JSONArray("[\"string\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "keyPathElementList");
JSONObject typeRecord = new JSONObject();
typeRecord.put("type", "array");
typeRecord.put("items", keyPathElementSchema);
fieldRecord.put("type", typeRecord);
fieldsArray.put(fieldRecord);
keyInfoSchema.put("fields", fieldsArray);
JSONObject partitionInfoSchema = new JSONObject();
partitionInfoSchema.put("name", "PartitionInfo");
partitionInfoSchema.put("type", "record");
fieldsArray = new JSONArray();
fieldRecord = new JSONObject();
fieldRecord.put("name", "partitionId");
typeArray = new JSONArray("[\"int\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "compoundKey");
typeArray = new JSONArray("[\"string\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "compoundValue");
typeArray = new JSONArray("[\"string\", \"null\"]");
fieldRecord.put("type", typeArray);
fieldsArray.put(fieldRecord);
fieldRecord = new JSONObject();
fieldRecord.put("name", "keyInfoList");
typeRecord = new JSONObject();
typeRecord.put("type", "array");
typeRecord.put("items", keyInfoSchema);
fieldRecord.put("type", typeRecord);
fieldsArray.put(fieldRecord);
partitionInfoSchema.put("fields", fieldsArray);
fieldRecord = new JSONObject();
fieldRecord.put("name", "S4__PartitionInfo");
typeRecord = new JSONObject();
typeRecord.put("type", "array");
typeRecord.put("items", partitionInfoSchema);
fieldRecord.put("type", typeRecord);
fieldsArray = jsonRecord.getJSONArray("fields");
fieldsArray.put(fieldRecord);
System.out.println(jsonRecord.toString(3));
} catch (Exception ioe) {
throw new RuntimeException(ioe);
} finally {
if (br != null)
try {
br.close();
} catch (Exception e) {
}
if (isr != null)
try {
isr.close();
} catch (Exception e) {
}
if (fr != null)
try {
fr.close();
} catch (Exception e) {
}
}
}
use of java.io.InputStreamReader in project scribejava by scribejava.
the class StreamUtils method getStreamContents.
/**
* Returns the stream contents as an UTF-8 encoded string
*
* @param is input stream
* @return string contents
* @throws java.io.IOException in any. SocketTimeout in example
*/
public static String getStreamContents(InputStream is) throws IOException {
Preconditions.checkNotNull(is, "Cannot get String from a null object");
final char[] buffer = new char[0x10000];
final StringBuilder out = new StringBuilder();
try (Reader in = new InputStreamReader(is, "UTF-8")) {
int read;
do {
read = in.read(buffer, 0, buffer.length);
if (read > 0) {
out.append(buffer, 0, read);
}
} while (read >= 0);
}
return out.toString();
}
use of java.io.InputStreamReader in project Conversations by siacs.
the class MemorizingTrustManager method getPoshFingerprintsFromServer.
private List<String> getPoshFingerprintsFromServer(String domain, String url, int maxTtl, boolean followUrl) {
Log.d("mtm", "downloading json for " + domain + " from " + url);
try {
List<String> results = new ArrayList<>();
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder builder = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
builder.append(inputLine);
}
JSONObject jsonObject = new JSONObject(builder.toString());
in.close();
int expires = jsonObject.getInt("expires");
if (expires <= 0) {
return new ArrayList<>();
}
if (maxTtl >= 0) {
expires = Math.min(maxTtl, expires);
}
String redirect;
try {
redirect = jsonObject.getString("url");
} catch (JSONException e) {
redirect = null;
}
if (followUrl && redirect != null && redirect.toLowerCase().startsWith("https")) {
return getPoshFingerprintsFromServer(domain, redirect, expires, false);
}
JSONArray fingerprints = jsonObject.getJSONArray("fingerprints");
for (int i = 0; i < fingerprints.length(); i++) {
JSONObject fingerprint = fingerprints.getJSONObject(i);
String sha256 = fingerprint.getString("sha-256");
if (sha256 != null) {
results.add(sha256);
}
}
writeFingerprintsToCache(domain, results, 1000L * expires + System.currentTimeMillis());
return results;
} catch (Exception e) {
Log.d("mtm", "error fetching posh " + e.getMessage());
return new ArrayList<>();
}
}
use of java.io.InputStreamReader in project AndResGuard by shwenzhang.
the class ResourceApkBuilder method generalRaw7zip.
private void generalRaw7zip() throws IOException, InterruptedException {
String outPath = m7zipOutPutDir.getAbsoluteFile().getAbsolutePath();
String path = outPath + File.separator + "*";
//极限压缩
String cmd = Utils.isPresent(config.m7zipPath) ? config.m7zipPath : TypedValue.COMMAND_7ZIP;
ProcessBuilder pb = new ProcessBuilder(cmd, "a", "-tzip", mSignedWith7ZipApk.getAbsolutePath(), path, "-mx9");
Process pro = pb.start();
InputStreamReader ir = new InputStreamReader(pro.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
//如果不读会有问题,被阻塞
while (input.readLine() != null) {
}
//destroy the stream
pro.waitFor();
pro.destroy();
}
Aggregations