Search in sources :

Example 31 with BufferedInputStream

use of java.io.BufferedInputStream in project OpenGrok by OpenGrok.

the class IndexDatabase method addFile.

/**
     * Add a file to the Lucene index (and generate a xref file)
     *
     * @param file The file to add
     * @param path The path to the file (from source root)
     * @throws java.io.IOException if an error occurs
     */
private void addFile(File file, String path) throws IOException {
    FileAnalyzer fa;
    try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
        fa = AnalyzerGuru.getAnalyzer(in, path);
    }
    for (IndexChangedListener listener : listeners) {
        listener.fileAdd(path, fa.getClass().getSimpleName());
    }
    fa.setCtags(ctags);
    fa.setProject(Project.getProject(path));
    fa.setScopesEnabled(RuntimeEnvironment.getInstance().isScopesEnabled());
    fa.setFoldingEnabled(RuntimeEnvironment.getInstance().isFoldingEnabled());
    Document doc = new Document();
    try (Writer xrefOut = getXrefWriter(fa, path)) {
        analyzerGuru.populateDocument(doc, file, path, fa, xrefOut);
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "Skipped file ''{0}'' because the analyzer didn''t " + "understand it.", path);
        LOGGER.log(Level.FINE, "Exception from analyzer " + fa.getClass().getName(), e);
        cleanupResources(doc);
        return;
    }
    try {
        writer.addDocument(doc);
    } catch (Throwable t) {
        cleanupResources(doc);
        throw t;
    }
    setDirty();
    for (IndexChangedListener listener : listeners) {
        listener.fileAdded(path, fa.getClass().getSimpleName());
    }
}
Also used : FileAnalyzer(org.opensolaris.opengrok.analysis.FileAnalyzer) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(org.apache.lucene.document.Document) FileInputStream(java.io.FileInputStream) IndexWriter(org.apache.lucene.index.IndexWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) HistoryException(org.opensolaris.opengrok.history.HistoryException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException)

Example 32 with BufferedInputStream

use of java.io.BufferedInputStream in project jersey by jersey.

the class ApacheConnector method getInputStream.

private static InputStream getInputStream(final CloseableHttpResponse response) throws IOException {
    final InputStream inputStream;
    if (response.getEntity() == null) {
        inputStream = new ByteArrayInputStream(new byte[0]);
    } else {
        final InputStream i = response.getEntity().getContent();
        if (i.markSupported()) {
            inputStream = i;
        } else {
            inputStream = new BufferedInputStream(i, ReaderWriter.BUFFER_SIZE);
        }
    }
    return new FilterInputStream(inputStream) {

        @Override
        public void close() throws IOException {
            response.close();
            super.close();
        }
    };
}
Also used : FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream)

Example 33 with BufferedInputStream

use of java.io.BufferedInputStream in project Openfire by igniterealtime.

the class BuildDate method getBuildDate.

public static String getBuildDate() {
    InputStream in = BuildDate.class.getResourceAsStream(BUILD_DATE);
    if (in == null) {
        return "Can't read " + BUILD_DATE;
    }
    in = new BufferedInputStream(in);
    int bytesAvailable = 0;
    try {
        bytesAvailable = in.available();
    } catch (IOException e) {
        return e.getMessage();
    }
    byte[] buf = new byte[bytesAvailable];
    try {
        in.read(buf, 0, bytesAvailable);
    } catch (IOException e) {
        return e.getMessage();
    }
    return new String(buf).trim();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 34 with BufferedInputStream

use of java.io.BufferedInputStream in project languagetool by languagetool-org.

the class POSTagLanguageModel method runOnStdIn.

private static void runOnStdIn(final JLanguageTool lt) throws IOException {
    final int MAX_FILE_SIZE = 64_000;
    InputStreamReader isr = null;
    BufferedReader br = null;
    StringBuilder sb = new StringBuilder();
    try {
        isr = new InputStreamReader(new BufferedInputStream(System.in));
        br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
            sb.append('\n');
            if (lt.getLanguage().getSentenceTokenizer().singleLineBreaksMarksPara()) {
                tagText(sb.toString(), lt);
                sb = new StringBuilder();
            } else {
                if ("".equals(line) || sb.length() >= MAX_FILE_SIZE) {
                    tagText(sb.toString(), lt);
                    sb = new StringBuilder();
                }
            }
        }
    } finally {
        if (sb.length() > 0) {
            tagText(sb.toString(), lt);
        }
    }
    br.close();
    isr.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) BufferedReader(java.io.BufferedReader)

Example 35 with BufferedInputStream

use of java.io.BufferedInputStream in project JessMA by ldcsaa.

the class FileDownloader method downloadStream.

private void downloadStream(HttpServletRequest request, HttpServletResponse response) throws IOException {
    int length = stream.available();
    Range<Integer> range = prepareDownload(request, response, length);
    InputStream is = new BufferedInputStream(stream);
    doDownload(response, is, range);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)3306 IOException (java.io.IOException)1660 FileInputStream (java.io.FileInputStream)1550 InputStream (java.io.InputStream)1473 File (java.io.File)886 BufferedOutputStream (java.io.BufferedOutputStream)499 FileOutputStream (java.io.FileOutputStream)467 ByteArrayInputStream (java.io.ByteArrayInputStream)330 URL (java.net.URL)298 FileNotFoundException (java.io.FileNotFoundException)273 DataInputStream (java.io.DataInputStream)263 OutputStream (java.io.OutputStream)253 ZipEntry (java.util.zip.ZipEntry)248 ByteArrayOutputStream (java.io.ByteArrayOutputStream)237 ArrayList (java.util.ArrayList)148 ZipInputStream (java.util.zip.ZipInputStream)143 GZIPInputStream (java.util.zip.GZIPInputStream)135 InputStreamReader (java.io.InputStreamReader)132 HttpURLConnection (java.net.HttpURLConnection)119 HashMap (java.util.HashMap)119