當前位置: 首頁>>代碼示例>>Java>>正文


Java LineIterator.close方法代碼示例

本文整理匯總了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();
	}
}
 
開發者ID:rhawan,項目名稱:microservices-tcc-alfa,代碼行數:19,代碼來源:CargaCliente.java

示例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();
	}
}
 
開發者ID:rhawan,項目名稱:microservices-tcc-alfa,代碼行數:18,代碼來源:CargaProduto.java

示例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);
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:22,代碼來源:FaqsDatasource.java

示例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();
	}
}
 
開發者ID:lithiumtech,項目名稱:flow,代碼行數:19,代碼來源:Lines.java

示例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);
}
 
開發者ID:ConnorLinfoot,項目名稱:CratesPlus,代碼行數:22,代碼來源:CratesPlus.java

示例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;
}
 
開發者ID:softwareloop,項目名稱:tstconfig,代碼行數:17,代碼來源:ConfigUtils.java

示例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();
    }
}
 
開發者ID:sokolm,項目名稱:LGA,代碼行數:29,代碼來源:NodeNamerImpl.java

示例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;
}
 
開發者ID:jenkinsci,項目名稱:gatekeeper-plugin,代碼行數:25,代碼來源:LogMessageSearcher.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:marmotta,代碼行數:30,代碼來源:GeonamesParser.java

示例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());
}
 
開發者ID:team-grit,項目名稱:grit,代碼行數:34,代碼來源:EntityHandler.java

示例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;
}
 
開發者ID:tudarmstadt-lt,項目名稱:topicrawler,代碼行數:41,代碼來源:LanguageModelHelper.java

示例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();
        }
    }
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:10,代碼來源:LineRecordReader.java

示例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);
    }
}
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:13,代碼來源:CSVSequenceRecordReader.java

示例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();
			}
		};
	};
}
 
開發者ID:lithiumtech,項目名稱:flow,代碼行數:31,代碼來源:Lines.java

示例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;
}
 
開發者ID:lithiumtech,項目名稱:flow,代碼行數:11,代碼來源:Lines.java


注:本文中的org.apache.commons.io.LineIterator.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。