use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class TroffAnalyzerTest method testAnalyze.
/**
* Test method for {@link org.opensolaris.opengrok.analysis.document
* .TroffAnalyzer#analyze(org.apache.lucene.document.Document,
* java.io.InputStream)}.
*
* @throws IOException
*/
@Test
public void testAnalyze() throws IOException {
Document doc = new Document();
StringWriter xrefOut = new StringWriter();
analyzer.analyze(doc, new StreamSource() {
@Override
public InputStream getStream() throws IOException {
return new ByteArrayInputStream(content.getBytes());
}
}, xrefOut);
}
use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class LineBreakerTest method shouldHandleDocsOfLongerLength.
@Test
public void shouldHandleDocsOfLongerLength() throws IOException {
// 0 0
// 0-- - 5-- - -1--- - 5--- - 2-
final String INPUT = "ab\r\ncde\r\nefgh\r\nijk\r\nlm";
StreamSource src = StreamSource.fromString(INPUT);
brkr.reset(src);
assertEquals("split count", 5, brkr.count());
assertEquals("split position", 0, brkr.getPosition(0));
assertEquals("split position", 4, brkr.getPosition(1));
assertEquals("split position", 9, brkr.getPosition(2));
assertEquals("split position", 15, brkr.getPosition(3));
assertEquals("split position", 20, brkr.getPosition(4));
}
use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class LineBreakerTest method shouldSplitEndingLFsIntoOneMoreLine.
@Test
public void shouldSplitEndingLFsIntoOneMoreLine() throws IOException {
StreamSource src = StreamSource.fromString("abc\ndef\n");
brkr.reset(src);
assertEquals("split count", 3, brkr.count());
assertEquals("split position", 0, brkr.getPosition(0));
assertEquals("split position", 4, brkr.getPosition(1));
assertEquals("split position", 8, brkr.getPosition(2));
}
use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class StreamUtils method sourceFromEmbedded.
/**
* Creates a {@code StreamSource} instance that reads data from an
* embedded resource.
* @param resourceName a required resource name
* @return a stream source that reads from {@code name}
*/
public static StreamSource sourceFromEmbedded(String resourceName) {
return new StreamSource() {
@Override
public InputStream getStream() throws IOException {
InputStream res = StreamUtils.class.getClassLoader().getResourceAsStream(resourceName);
assertNotNull("resource " + resourceName, res);
return new BufferedInputStream(res);
}
};
}
use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class GZIPAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
StreamSource gzSrc = wrap(src);
String path = doc.get("path");
if (path != null && (path.endsWith(".gz") || path.endsWith(".GZ") || path.endsWith(".Gz"))) {
String newname = path.substring(0, path.length() - 3);
// System.err.println("GZIPPED OF = " + newname);
try (InputStream gzis = gzSrc.getStream()) {
fa = AnalyzerGuru.getAnalyzer(gzis, newname);
}
if (fa == null) {
this.g = Genre.DATA;
LOGGER.log(Level.WARNING, "Did not analyze {0}, detected as data.", newname);
// TODO we could probably wrap tar analyzer here, need to do research on reader coming from gzis ...
} else {
// simple file gziped case captured here
if (fa.getGenre() == Genre.PLAIN || fa.getGenre() == Genre.XREFABLE) {
this.g = Genre.XREFABLE;
} else {
this.g = Genre.DATA;
}
fa.analyze(doc, gzSrc, xrefOut);
if (doc.get("t") != null) {
doc.removeField("t");
if (g == Genre.XREFABLE) {
doc.add(new Field("t", g.typeName(), AnalyzerGuru.string_ft_stored_nanalyzed_norms));
}
}
}
}
}
Aggregations