use of java.io.BufferedReader in project torodb by torodb.
the class ConfigUtils method getPasswordFromPassFile.
private static String getPasswordFromPassFile(String passFile, String host, int port, String database, String user) throws FileNotFoundException, IOException {
File pass = new File(passFile);
if (pass.exists() && pass.canRead() && pass.isFile()) {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(pass), Charsets.UTF_8));
try {
String line;
int index = 0;
while ((line = br.readLine()) != null) {
index++;
String[] passChunks = line.split(":");
if (passChunks.length != 5) {
LOGGER.warn("Wrong format at line " + index + " of file " + passFile);
continue;
}
if ((passChunks[0].equals("*") || passChunks[0].equals(host)) && (passChunks[1].equals("*") || passChunks[1].equals(String.valueOf(port))) && (passChunks[2].equals("*") || passChunks[2].equals(database)) && (passChunks[3].equals("*") || passChunks[3].equals(user))) {
return passChunks[4];
}
}
br.close();
} finally {
br.close();
}
}
return null;
}
use of java.io.BufferedReader 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.BufferedReader 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.BufferedReader 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.BufferedReader in project disunity by ata4.
the class StringTable method commonStrings.
public static BiMap<Integer, String> commonStrings(int version) throws IOException {
// load default strings from resource files if required
if (!commonStringMap.containsKey(version)) {
AtomicInteger index = new AtomicInteger(1 << 31);
String resourcePath = "/resources/strings/" + version + ".x.txt";
try (BufferedReader br = resourceReader(resourcePath)) {
commonStringMap.put(version, br.lines().collect(Collectors.toMap(value -> index.getAndAdd(value.length() + 1), value -> value)));
} catch (NullPointerException ex) {
throw new RuntimeException("No common strings file found for version " + version);
}
}
return HashBiMap.create(commonStringMap.get(version));
}
Aggregations