本文整理匯總了Java中org.apache.commons.io.LineIterator.nextLine方法的典型用法代碼示例。如果您正苦於以下問題:Java LineIterator.nextLine方法的具體用法?Java LineIterator.nextLine怎麽用?Java LineIterator.nextLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.io.LineIterator
的用法示例。
在下文中一共展示了LineIterator.nextLine方法的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: 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();
}
}
示例3: 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();
}
}
示例4: fileToCodeList
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
public static List<Code> fileToCodeList(String fileName) {
List<Code> codes = new ArrayList<>();
try {
LineIterator it = getLineIterator(fileName);
while (it.hasNext()) {
String line = it.nextLine();
if (line.equals("") || line.startsWith("#"))
continue;
String[] parts = line.split(";", 2);
codes.add((new Code(parts[0], parts[1])));
}
} catch (IOException e) {
e.printStackTrace();
}
return codes;
}
示例5: converteerAfnemerindicatiebestand
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
private void converteerAfnemerindicatiebestand(final long maxAfnemerindicatieId,
final OutputStream os, final LineIterator it) throws IOException {
long voortgang = 0;
final Map<Short, Short> partijConversieMap = partijConversie.getPartijConversieMap();
final Map<Integer, Integer> leveringsautorisatieConversieMap = leveringsautorisatieConversie.getLeveringsautorisatieConversieMap();
while (it.hasNext()) {
final String line = it.nextLine();
final String[] splitLine = StringUtils.split(line, ",");
final long origId = Long.parseLong(splitLine[0]);
final long id = maxAfnemerindicatieId + origId;
final String pers = splitLine[1];
final String afnemer = String.valueOf(partijConversieMap.get(Short.parseShort(splitLine[2])));
final String levsautorisatie = String.valueOf(leveringsautorisatieConversieMap.get(Integer.parseInt(splitLine[3])));
final String dataanvmaterieleperiode = StringUtils.defaultString(StringUtils.trimToNull(splitLine[4]), NULL_VALUE);
final String dateindevolgen = StringUtils.defaultString(StringUtils.trimToNull(splitLine[5]), NULL_VALUE);
final String indag = splitLine[6];
final String newLine = String.format("%s,%s,%s,%s,%s,%s,%s%n", id, pers, afnemer, levsautorisatie,
dataanvmaterieleperiode, dateindevolgen, indag);
IOUtils.write(newLine, os, StandardCharsets.UTF_8);
voortgang++;
if (voortgang % LOG_TRESHOLD == 0) {
LOGGER.info("Voortgang persafnemerindicatie {}", voortgang);
}
}
}
示例6: 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
}
}
示例7: 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;
}
示例8: createInputFile
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
public static void createInputFile(Configuration conf, Path file, Path targetFile,
String startNode)
throws IOException {
FileSystem fs = file.getFileSystem(conf);
OutputStream os = fs.create(targetFile);
LineIterator iter = org.apache.commons.io.IOUtils
.lineIterator(fs.open(file), "UTF8");
while (iter.hasNext()) {
String line = iter.nextLine();
String[] parts = StringUtils.split(line);
int distance = Node.INFINITE;
if (startNode.equals(parts[0])) {
distance = 0;
}
IOUtils.write(parts[0] + '\t' + String.valueOf(distance) + "\t\t",
os);
IOUtils.write(StringUtils.join(parts, '\t', 1, parts.length), os);
IOUtils.write("\n", os);
}
os.close();
}
示例9: createInputFile
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
public static int createInputFile(Path file, Path targetFile)
throws IOException {
Configuration conf = new Configuration();
FileSystem fs = file.getFileSystem(conf);
int numNodes = getNumNodes(file);
double initialPageRank = 1.0 / (double) numNodes;
OutputStream os = fs.create(targetFile);
LineIterator iter = IOUtils
.lineIterator(fs.open(file), "UTF8");
while (iter.hasNext()) {
String line = iter.nextLine();
String[] parts = StringUtils.split(line);
Node node = new Node()
.setPageRank(initialPageRank)
.setAdjacentNodeNames(
Arrays.copyOfRange(parts, 1, parts.length));
IOUtils.write(parts[0] + '\t' + node.toString() + '\n', os);
}
os.close();
return numNodes;
}
示例10: getNext
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
@Override
public void getNext(JCas aJcas) throws IOException, CollectionException {
File f = documents.get(i);
LineIterator it = FileUtils.lineIterator(f);
int start =0;
int inds=0;
StringBuffer sb = new StringBuffer();
while(it.hasNext()){
String line = it.nextLine();
Sentence sent = new Sentence(aJcas, start, start+line.length());
sent.addToIndexes();
start = start + line.length() + 1;
sb.append(line+"\n");
if (inds%10000==0)
System.out.println("R"+inds);
}
aJcas.setDocumentText(sb.toString());
//had to add english as default language, one could also add another configuration parameter
aJcas.setDocumentLanguage("en");
i++;
}
示例11: readFrequentSequences
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
/** Read in frequent sequences (sorted by support) */
public static SortedMap<Sequence, Integer> readFrequentSequences(final File output) throws IOException {
final HashMap<Sequence, Integer> sequences = new HashMap<>();
final LineIterator it = FileUtils.lineIterator(output);
while (it.hasNext()) {
final String line = it.nextLine();
if (!line.trim().isEmpty()) {
final String[] splitLine = line.split("#SUP:");
final String[] items = splitLine[0].trim().split("-1");
final Sequence seq = new Sequence();
for (final String item : items)
seq.add(Integer.parseInt(item.trim()));
final int supp = Integer.parseInt(splitLine[1].trim());
sequences.put(seq, supp);
}
}
// Sort sequences by support
final Ordering<Sequence> comparator = Ordering.natural().reverse().onResultOf(Functions.forMap(sequences))
.compound(Ordering.usingToString());
return ImmutableSortedMap.copyOf(sequences, comparator);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: readSQSSequences
import org.apache.commons.io.LineIterator; //導入方法依賴的package包/類
/** Read in SQS sequences (sorted by worth) */
public static LinkedHashMap<Sequence, Double> readSQSSequences(final File output) throws IOException {
final LinkedHashMap<Sequence, Double> sequences = new LinkedHashMap<>();
final LineIterator it = FileUtils.lineIterator(output);
while (it.hasNext()) {
final String line = it.nextLine();
if (!line.trim().isEmpty()) {
final String[] splitLine = line.split(" ");
final String[] items = splitLine[0].split(" ");
final Sequence seq = new Sequence();
for (final String item : items)
seq.add(Integer.parseInt(item));
final double worth = Double.parseDouble(splitLine[1].split(" ")[1]);
sequences.put(seq, worth);
}
}
return sequences;
}