本文整理汇总了Java中org.apache.commons.io.LineIterator.close方法的典型用法代码示例。如果您正苦于以下问题:Java LineIterator.close方法的具体用法?Java LineIterator.close怎么用?Java LineIterator.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.LineIterator
的用法示例。
在下文中一共展示了LineIterator.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: realizarCargaArquivo
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public void realizarCargaArquivo() {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(NOME_ARQUIVO).getFile());
LineIterator it = null;
try {
it = FileUtils.lineIterator(file, "UTF-8");
while(it.hasNext()) {
String linha = it.nextLine();
String[] dados = linha.split("\\|");
inserirCliente(dados[0], dados[1], dados[2], dados[3], dados[4],
dados[5], dados[6], dados[7], dados[8], dados[9]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
it.close();
}
}
示例2: realizarCargaArquivo
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public void realizarCargaArquivo() {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(NOME_ARQUIVO).getFile());
LineIterator it = null;
try {
it = FileUtils.lineIterator(file, "UTF-8");
while(it.hasNext()) {
String linha = it.nextLine();
String[] dados = linha.split("\\|");
inserirItemAvaliado(dados[0], dados[1], dados[2], dados[3], dados[4]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
it.close();
}
}
示例3: createProjFile
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private void createProjFile(String file, String projectLabel) {
File template = new File(FAQ_DIR+File.separator+"whc_template"+File.separator+"project.html");
StringBuffer buf = new StringBuffer();
String title = StringEscapeUtils.escapeHtml(projectLabel);
LineIterator it = null;
try {
it = FileUtils.lineIterator(template, "UTF-8");
try {
while (it.hasNext()) {
String line = it.nextLine();
line = line.replaceAll("\\$title", title);
buf.append(line+CRLF);
}
} finally {
it.close();
}
} catch (Exception e) {
LOGGER.error("Can't copy project.html template file: " + e.getMessage());
}
writeFile(buf.toString(), file);
}
示例4: accept
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static void accept(@Nonnull InputStream in, @Nonnull Charset charset,
@Nonnull CheckedConsumer<String, IOException> consumer) throws IOException {
checkNotNull(in);
checkNotNull(charset);
checkNotNull(consumer);
LineIterator it = IOUtils.lineIterator(in, charset);
try {
while (it.hasNext()) {
consumer.accept(it.nextLine());
}
} catch (IllegalStateException e) {
Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
throw new IOException(e);
} finally {
it.close();
}
}
示例5: uploadFile
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public String uploadFile(String fileName) {
File file = new File(getDataFolder(), fileName);
if (!file.exists())
return null;
LineIterator it;
String lines = "";
try {
it = FileUtils.lineIterator(file, "UTF-8");
try {
while (it.hasNext()) {
String line = it.nextLine();
lines = lines + line + "\n";
}
} finally {
it.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return MCDebug.paste(fileName, lines);
}
示例6: readLinesFromFile
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static List<String> readLinesFromFile(
String filename, String encoding
) throws IOException {
List<String> lines = new ArrayList<String>();
File file = new File(filename);
LineIterator it = FileUtils.lineIterator(file, encoding);
try {
while (it.hasNext()) {
String line = it.nextLine();
lines.add(line);
}
} finally {
it.close();
}
return lines;
}
示例7: load
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* List of lines are generated from a given file. then this list is used to generate a NodeNamerImpl
*
* @param file
* @return INodeNamer
* @throws IOException
*/
public static INodeNamer load(final File file) throws IOException {
final int numNodes = countLines(file, Encoding.DEFAULT_CHARSET_NAME);
final Int2ObjectOpenHashMap<String> id2Label = new Int2ObjectOpenHashMap<String>(numNodes);
final Object2IntOpenHashMap<String> label2Id = new Object2IntOpenHashMap<String>(numNodes);
final LineIterator it = FileUtils.lineIterator(file, Encoding.DEFAULT_CHARSET_NAME);
try {
int curId = 0;
while(it.hasNext()) {
final String nodeName = it.next();
id2Label.put(curId, nodeName);
label2Id.put(nodeName, curId);
curId++;
}
return new NodeNamerImpl(id2Label, label2Id);
} finally {
it.close();
}
}
示例8: searchForMessages
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Searches build log for messages.
* @param keyword Keyword to look for in log.
* @return List of messages found.
*/
public List<String> searchForMessages(String keyword) throws IOException {
final File logFile = build.getLogFile();
LineIterator it = FileUtils.lineIterator(logFile, "UTF-8");
List<String> resultList = new ArrayList<String>();
try {
while (it.hasNext()) {
String line = it.nextLine();
if (line.contains(keyword)) {
resultList.add(line);
}
}
} finally {
it.close();
}
return resultList;
}
示例9: parse
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Parses the data from the supplied InputStream, using the supplied baseURI
* to resolve any relative URI references.
*
* @param in The InputStream from which to read the data.
* @param baseURI The URI associated with the data in the InputStream.
* @throws java.io.IOException If an I/O error occurred while data was read from the InputStream.
* @throws org.openrdf.rio.RDFParseException If the parser has found an unrecoverable parse error.
* @throws org.openrdf.rio.RDFHandlerException If the configured statement handler has encountered an
* unrecoverable error.
*/
@Override
public void parse(InputStream in, String baseURI) throws IOException, RDFParseException, RDFHandlerException {
LineIterator it = IOUtils.lineIterator(in, RDFFormat.RDFXML.getCharset());
try {
while(it.hasNext()) {
lineNumber++;
String line = it.nextLine();
if(lineNumber % 2 == 0) {
// only odd line numbers contain triples
StringReader buffer = new StringReader(line);
lineParser.parse(buffer, baseURI);
}
}
} finally {
it.close();
}
}
示例10: getQualifiedNameFromFile
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Iterates over a java source file, and identifies the fully qualified
* name of the class from the package declaration in the source.
*
* @param sourceFile
* a java source file
* @return the fully qualified name of the class
* @throws IOException
* if the source file can not be read from.
*/
private String getQualifiedNameFromFile(Path sourceFile)
throws IOException {
final String packageRegex = "package\\s[^,;]+;";
LineIterator it;
String result = "";
it = FileUtils.lineIterator(sourceFile.toFile(), "UTF-8");
// look for the line identifying the package
while (it.hasNext()) {
final String line = it.nextLine();
if (line.matches(packageRegex)) {
result = line;
// strip not needed elements (the word package)
result = result.substring(8, result.length() - 1);
it.close();
result = result + ".";
break;
}
}
it.close();
// append the classname
return result + FilenameUtils.getBaseName(sourceFile.toString());
}
示例11: createCountingLmTxtFilesInDirectory
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static LanguageModel<String> createCountingLmTxtFilesInDirectory(AbstractStringProvider stringProvider, File srcdir, int order) {
CountingLM<String> lm = new CountingLM<String>(order);
stringProvider.setLanguageModel(lm);
File[] txtfiles = srcdir.listFiles(new java.io.FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".txt");
}
});
String[] basenames = new String[txtfiles.length];
for(int i = 0; i < basenames.length; i++)
basenames[i] = txtfiles[i].getName();
LOG.info(String.format("Reading language model from dir: '%s'; Files: %s.", srcdir.getAbsolutePath(), StringUtils.abbreviate(Arrays.toString(basenames), 200)));
for(int i = 0; i < txtfiles.length; i++){
File txtfile = txtfiles[i];
LOG.debug("Processing file {} / {} ('{}')", i+1, txtfiles.length, txtfile.getAbsolutePath());
try {
LineIterator liter = new LineIterator(new BufferedReader(new InputStreamReader(new FileInputStream(txtfile))));
int lc = 0;
while(liter.hasNext()){
LOG.trace("Processing line {})", ++lc);
for(List<String> ngram : stringProvider.getNgrams(liter.next()))
lm.addNgram(ngram);
}
liter.close();
} catch (Exception e) {
LOG.warn("Could not read file {}", txtfile.getAbsolutePath(), e);
}
}
LOG.info("Fixing LM ... ");
lm.fixItNow();
LOG.info("Fixing LM finished.");
return lm;
}
示例12: close
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
if (iter != null) {
if (iter instanceof LineIterator) {
LineIterator iter2 = (LineIterator) iter;
iter2.close();
}
}
}
示例13: loadAndClose
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private List<List<Writable>> loadAndClose(InputStream inputStream) {
LineIterator lineIter = null;
try {
lineIter = IOUtils.lineIterator(new BufferedReader(new InputStreamReader(inputStream)));
return load(lineIter);
} finally {
if (lineIter != null) {
lineIter.close();
}
IOUtils.closeQuietly(inputStream);
}
}
示例14: iterate
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Nonnull
public static Iterable<String> iterate(@Nonnull InputStream in, @Nonnull Charset charset) throws IOException {
checkNotNull(in);
checkNotNull(charset);
LineIterator it = IOUtils.lineIterator(in, charset);
AtomicBoolean used = new AtomicBoolean();
return () -> {
if (used.getAndSet(true)) {
throw new RuntimeException("this iterable can only be used once");
}
return new Iterator<String>() {
@Override
public boolean hasNext() {
boolean next = it.hasNext();
if (!next) {
it.close();
}
return next;
}
@Override
public String next() {
return it.nextLine();
}
};
};
}
示例15: first
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Nonnull
public static String first(@Nonnull InputStream in, @Nonnull Charset charset) throws IOException {
checkNotNull(in);
LineIterator it = IOUtils.lineIterator(in, charset);
String line = it.hasNext() ? it.nextLine() : "";
it.close();
return line;
}