本文整理汇总了Java中org.apache.commons.io.LineIterator.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java LineIterator.closeQuietly方法的具体用法?Java LineIterator.closeQuietly怎么用?Java LineIterator.closeQuietly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.LineIterator
的用法示例。
在下文中一共展示了LineIterator.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSearchTextPresentInLinesOfFile
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private boolean isSearchTextPresentInLinesOfFile(File f) {
LineIterator it = null;
try {
it = FileUtils.lineIterator(f, "UTF-8");
while (it.hasNext()) {
String line = it.nextLine();
if (line.contains(searchText)) {
return true;
}
}
return false;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
LineIterator.closeQuietly(it);
}
}
示例2: run
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Override
public void run() {
LineIterator it = null;
try {
it = IOUtils.lineIterator(inputStream, "UTF-8");
while (it.hasNext()) {
String line = it.nextLine();
LOGGER.debug(line);
if (filtered) {
filtered = filter(line);
}
}
} catch (IOException ioe) {
LOGGER.debug("Error consuming input stream: {}", ioe.getMessage());
} catch (IllegalStateException ise) {
LOGGER.debug("Error reading from closed input stream: {}", ise.getMessage());
} finally {
LineIterator.closeQuietly(it); // clean up all associated resources
}
}
示例3: loadFields
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private Set<String> loadFields() {
Set<String> fields = Sets.newHashSet();
LineIterator it;
try {
it = FileUtils.lineIterator(_fieldsFile);
} catch (IOException ex) {
throw new OpenGammaRuntimeException("IOException when reading " + _fieldsFile, ex);
}
try {
while (it.hasNext()) {
String line = it.nextLine();
if (StringUtils.isBlank(line) || line.charAt(0) == '#') {
continue;
}
fields.add(line);
}
} finally {
LineIterator.closeQuietly(it);
}
return fields;
}
示例4: writeDefaultStyle
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Writes the default system test style definition.
*/
protected void writeDefaultStyle()
{
xmlWriter_.writeElementStart( "STYLE");
xmlWriter_.indent();
LineIterator styleLines = null;
try
{
for( styleLines = IOUtils.lineIterator( getClass().getResourceAsStream( "system-test.css"), "UTF-8");
styleLines.hasNext();
xmlWriter_.println( styleLines.next()));
}
catch( Exception e)
{
throw new RuntimeException( "Can't write resource=system-test.css", e);
}
finally
{
LineIterator.closeQuietly( styleLines);
}
xmlWriter_.unindent();
xmlWriter_.writeElementEnd( "STYLE");
}
示例5: writeDefaultScript
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Writes the default system test presentation script.
*/
protected void writeDefaultScript()
{
xmlWriter_.writeElementStart( "SCRIPT");
xmlWriter_.indent();
LineIterator scriptLines = null;
try
{
for( scriptLines = IOUtils.lineIterator( getClass().getResourceAsStream( "system-test.js"), "UTF-8");
scriptLines.hasNext();
xmlWriter_.println( scriptLines.next()));
}
catch( Exception e)
{
throw new RuntimeException( "Can't write resource=system-test.js", e);
}
finally
{
LineIterator.closeQuietly( scriptLines);
}
xmlWriter_.unindent();
xmlWriter_.writeElementEnd( "SCRIPT");
}
示例6: getUndesiredTermsToFilterOut
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static Set<String> getUndesiredTermsToFilterOut(String filename) {
Set<String> result = new HashSet<String>();
File file = new File(FOLDER_PATH + filename);
LineIterator it = null;
try {
it = FileUtils.lineIterator(file);
while (it.hasNext()) {
result.add(it.next().trim().toLowerCase());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
LineIterator.closeQuietly(it);
}
return result;
}
示例7: getUndesiredConceptsToFilterOut
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static Set<Integer> getUndesiredConceptsToFilterOut() {
Set<Integer> things = new HashSet<Integer>();
// InputStreamReader(JochemCurator.class.getResourceAsStream("conceptsToRemove.txt")));
File file = new File(FOLDER_PATH + "conceptsToRemove.txt");
LineIterator it = null;
try {
it = FileUtils.lineIterator(file);
while (it.hasNext()) {
String conceptLine = it.next().trim();
String[] conceptNumbers = conceptLine.split(";");
for (String conceptNumber : conceptNumbers) {
if (conceptNumber.length() != 0)
things.add(Integer.parseInt(conceptNumber));
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
LineIterator.closeQuietly(it);
}
return things;
}
示例8: getPharmaceuticalCompanies
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static Set<String> getPharmaceuticalCompanies() {
Set<String> result = new HashSet<String>();
// InputStreamReader(JochemCurator.class.getResourceAsStream("pharmaceuticalCompanies.txt")));
File file = new File(FOLDER_PATH + "pharmaceuticalCompanies.txt");
LineIterator it = null;
try {
it = FileUtils.lineIterator(file);
while (it.hasNext()) {
result.add(it.next().trim().toLowerCase());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
LineIterator.closeQuietly(it);
}
return result;
}
示例9: loadContext
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* Load the content of the context file.
*
* @param path path of the context File.
* @return Context loaded.
* @throws IOException if file not found.
* @throws MalformedContextFileException if the Context file don't have the right structure.
* @throws IllogicalContextException if an image is bigger than pattern max size.
*/
public static Context loadContext(String path) throws IOException, MalformedContextFileException, IllogicalContextException {
File file = new File(path);
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
ArrayList<Box> boxes = new ArrayList<>();
try {
Double x = loadLine(it, "^LX=[0-9]{1,13}(\\.[0-9]*)?$");
Double y = loadLine(it, "LY=[0-9]{1,13}(\\.[0-9]*)?");
int cost = loadLine(it, "m=[0-9]{1,13}(\\.[0-9]*)?").intValue();
while (it.hasNext()) {
boxes.add(loadBox(it.nextLine()));
}
LineIterator.closeQuietly(it);
double max = Math.max(x, y);
if (boxes.parallelStream().anyMatch(b -> b.getSize().getX() > max) ||
boxes.parallelStream().anyMatch(b -> b.getSize().getY() > max)) {
throw new IllogicalContextException("There is an image which is bigger than the pattern.");
}
return new Context(file.getName(), 20, 1, boxes, new Vector(x, y));
} catch (MalformedContextFileException mctx) {
throw mctx;
} finally {
LineIterator.closeQuietly(it);
}
}
示例10: readTransactions
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static TransactionList readTransactions(final File inputFile) throws IOException {
final List<Transaction> transactions = new ArrayList<>();
// for each line (transaction) until the end of file
final LineIterator it = FileUtils.lineIterator(inputFile, "UTF-8");
while (it.hasNext()) {
final String line = it.nextLine();
// if the line is a comment, is empty or is a
// kind of metadata
if (line.isEmpty() == true || line.charAt(0) == '#' || line.charAt(0) == '%' || line.charAt(0) == '@') {
continue;
}
// split the transaction into items
final String[] lineSplited = line.split(" ");
// convert to Transaction class and add it to the structure
transactions.add(getTransaction(lineSplited));
}
// close the input file
LineIterator.closeQuietly(it);
return new TransactionList(transactions);
}
示例11: printTransactionDBStats
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/** Print useful statistics for the transaction database */
public static void printTransactionDBStats(final File dbFile) throws IOException {
int noTransactions = 0;
double sparsity = 0;
final Set<Integer> singletons = new HashSet<>();
final LineIterator it = FileUtils.lineIterator(dbFile, "UTF-8");
while (it.hasNext()) {
final String[] items = it.nextLine().replace("-2", "").split(" -1 ");
for (final String item : items)
singletons.add(Integer.parseInt(item));
sparsity += items.length;
noTransactions++;
}
LineIterator.closeQuietly(it);
System.out.println("\nDatabase: " + dbFile);
System.out.println("Items: " + singletons.size());
System.out.println("Transactions: " + noTransactions);
System.out.println("Avg. items per transaction: " + sparsity / noTransactions + "\n");
}
示例12: getOriginal
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* @return the original sentence
*/
public String getOriginal() {
String sent = null;
LineIterator iterator = null;
try {
iterator = FileUtils.lineIterator(doc.getDocLoc());
} catch (final IOException e) {
e.printStackTrace();
}
for (int sentID = 0; iterator.hasNext(); sentID++) {
if (sentID == nsent) {
sent = iterator.nextLine().trim();
break;
}
iterator.nextLine();
}
LineIterator.closeQuietly(iterator);
return sent;
}
示例13: printTransactionDBStats
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/** Print useful statistics for the transaction database */
public static void printTransactionDBStats(final File dbFile)
throws IOException {
int noTransactions = 0;
double sparsity = 0;
final Set<Integer> singletons = new HashSet<>();
final LineIterator it = FileUtils.lineIterator(dbFile, "UTF-8");
while (it.hasNext()) {
final String[] items = it.nextLine().trim().split(" ");
for (final String item : items)
singletons.add(Integer.parseInt(item));
sparsity += items.length;
noTransactions++;
}
LineIterator.closeQuietly(it);
System.out.println("\nDatabase: " + dbFile);
System.out.println("Items: " + singletons.size());
System.out.println("Transactions: " + noTransactions);
System.out.println("Avg. items per transaction: " + sparsity
/ noTransactions + "\n");
}
示例14: getOriginal
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
* @return the original document text
*/
public String getOriginal() {
final StringBuffer doc = new StringBuffer();
LineIterator iterator = null;
try {
iterator = FileUtils.lineIterator(docLoc);
} catch (final IOException e) {
e.printStackTrace();
}
while (iterator.hasNext())
doc.append(iterator.nextLine().trim() + "\n");
LineIterator.closeQuietly(iterator);
return doc.toString();
}
示例15: readStopWords
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
static public LinkedList<String> readStopWords(String pathToStopwordsFile){
LinkedList<String> stopWords = new LinkedList<>();
if(pathToStopwordsFile != null){
LineIterator it = null;
try {
it = FileUtils.lineIterator(new File(pathToStopwordsFile), "UTF-8");
while (it.hasNext()) {
stopWords.add(it.nextLine());
}
} catch (IOException ex) {
Logger.getLogger(MABED.class.getName()).log(Level.SEVERE, null, ex);
} finally {
LineIterator.closeQuietly(it);
}
}
return stopWords;
}