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());
}
}
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();
}
};
}
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();
}
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();
}
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);
}
Aggregations