Search in sources :

Example 46 with BufferedReader

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 47 with BufferedReader

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 48 with BufferedReader

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;
}
Also used : Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) InputStreamReader(java.io.InputStreamReader) ZipEntry(java.util.zip.ZipEntry) BufferedReader(java.io.BufferedReader)

Example 49 with BufferedReader

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
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 50 with BufferedReader

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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedReader(java.io.BufferedReader)

Aggregations

BufferedReader (java.io.BufferedReader)5548 InputStreamReader (java.io.InputStreamReader)3430 IOException (java.io.IOException)2601 FileReader (java.io.FileReader)1283 File (java.io.File)942 InputStream (java.io.InputStream)845 ArrayList (java.util.ArrayList)766 FileInputStream (java.io.FileInputStream)694 URL (java.net.URL)526 Test (org.junit.Test)447 FileNotFoundException (java.io.FileNotFoundException)380 StringReader (java.io.StringReader)340 BufferedWriter (java.io.BufferedWriter)242 HashMap (java.util.HashMap)232 HttpURLConnection (java.net.HttpURLConnection)231 Matcher (java.util.regex.Matcher)223 OutputStreamWriter (java.io.OutputStreamWriter)212 PrintWriter (java.io.PrintWriter)208 URLConnection (java.net.URLConnection)208 Reader (java.io.Reader)201