本文整理了Java中org.apache.tika.io.IOUtils.readLines()
方法的一些代码示例,展示了IOUtils.readLines()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readLines()
方法的具体详情如下:
包路径:org.apache.tika.io.IOUtils
类名称:IOUtils
方法名:readLines
[英]Get the contents of an InputStream
as a list of Strings, one entry per line, using the default character encoding of the platform.
This method buffers the input internally, so there is no need to use a BufferedInputStream
.
[中]使用平台的默认字符编码,以字符串列表的形式获取InputStream
的内容,每行一个条目。
此方法在内部缓冲输入,因此无需使用BufferedInputStream
。
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input) throws IOException {
InputStreamReader reader = new InputStreamReader(input, UTF_8);
return readLines(reader);
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @param encoding the encoding to use, null means platform default
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input, String encoding) throws IOException {
if (encoding == null) {
return readLines(input);
} else {
InputStreamReader reader = new InputStreamReader(input, encoding);
return readLines(reader);
}
}
代码示例来源:origin: apache/tika
private Map<String, String> getTestLanguages(String resourceName) throws IOException {
Map<String, String> result = new HashMap<>();
List<String> languages = IOUtils.readLines(OptimaizeLangDetectorTest.class.getResourceAsStream(resourceName));
for (String line : languages) {
line = line.trim();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
String[] pieces = line.split("\t", 2);
if (pieces.length != 2) {
throw new IllegalArgumentException("Invalid language data line: " + line);
}
result.put(pieces[0], pieces[1]);
}
return result;
}
代码示例来源:origin: mulesoft/mule
private void findAndValidate(MuleArtifactClassLoader classLoader, String request, String resourceName,
URL expectedArtifactLocation, String expectedLine)
throws IOException {
URL resource = classLoader.findResource(request + ":" + resourceName);
assertThat(resource, is(notNullValue()));
assertThat(resource, is(equalTo(new URL("jar:" + expectedArtifactLocation.toString() + "!/" + resourceName))));
assertThat(readLines(resource.openStream()).get(0), is(expectedLine));
}
代码示例来源:origin: apache/tika
protected String[] getTestLanguages() throws IOException {
List<String> result = new ArrayList<>();
List<String> lines = IOUtils.readLines(LanguageDetectorTest.class.getResourceAsStream("language-codes.txt"));
for (String line : lines) {
line = line.trim();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
String[] parsed = line.split("\t");
String language = parsed[0];
if (hasTestLanguage(language)) {
result.add(language);
}
}
return result.toArray(new String[result.size()]);
}
代码示例来源:origin: org.apache.tika/tika-core
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input) throws IOException {
InputStreamReader reader = new InputStreamReader(input, UTF_8);
return readLines(reader);
}
代码示例来源:origin: apache/tika
@Test
public void test() throws Exception {
assumeTrue(TextLangDetector.canRun());
LanguageDetector detector = new TextLangDetector();
LanguageWriter writer = new LanguageWriter(detector);
List<String> lines = IOUtils.readLines(TextLangDetectorTest.class.getResourceAsStream("text-test.tsv"));
for (String line : lines) {
String[] data = line.split("\t");
if (data.length != 2) continue;
writer.reset();
writer.append(data[1]);
LanguageResult result = detector.detect();
assertNotNull(result);
assertEquals(data[0], result.getLanguage());
}
writer.close();
}
}
代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-core
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @param encoding the encoding to use, null means platform default
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input, String encoding) throws IOException {
if (encoding == null) {
return readLines(input);
} else {
InputStreamReader reader = new InputStreamReader(input, encoding);
return readLines(reader);
}
}
代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-core
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input) throws IOException {
InputStreamReader reader = new InputStreamReader(input, UTF_8);
return readLines(reader);
}
代码示例来源:origin: org.apache.tika/tika-core
/**
* Get the contents of an <code>InputStream</code> as a list of Strings,
* one entry per line, using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from, not null
* @param encoding the encoding to use, null means platform default
* @return the list of Strings, never null
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static List<String> readLines(InputStream input, String encoding) throws IOException {
if (encoding == null) {
return readLines(input);
} else {
InputStreamReader reader = new InputStreamReader(input, encoding);
return readLines(reader);
}
}
代码示例来源:origin: apache/tika
@Test
public void testLanguageDetection() throws Exception {
LanguageDetector detector = new Lingo24LangDetector();
assumeTrue(((Lingo24LangDetector) detector).isAvailable());
LanguageWriter writer = new LanguageWriter(detector);
// Reusing the test data from OptimaizeLangDetectorTest
List<String> lines = IOUtils.readLines(Lingo24LangDetectorTest.class.getResourceAsStream("text-test.tsv"));
for (String line : lines) {
String[] data = line.split("\t");
if (data.length != 2) continue;
writer.reset();
writer.append(data[1]);
// Only check supported languages
if (detector.hasModel(data[0])) {
LanguageResult result = detector.detect();
assertNotNull(result);
assertEquals(data[0], result.getLanguage());
}
}
writer.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!