本文整理汇总了Java中org.apache.commons.io.LineIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java LineIterator.hasNext方法的具体用法?Java LineIterator.hasNext怎么用?Java LineIterator.hasNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.LineIterator
的用法示例。
在下文中一共展示了LineIterator.hasNext方法的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: sendGet
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public DockerResponse sendGet(URI uri) throws JSONClientException {
if (logger.isDebugEnabled()) {
logger.debug("Send a get request to : " + uri);
}
StringBuilder builder = new StringBuilder();
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = null;
try {
CloseableHttpClient httpclient = buildSecureHttpClient();
response = httpclient.execute(httpGet);
LineIterator iterator = IOUtils.lineIterator(response.getEntity()
.getContent(), "UTF-8");
while (iterator.hasNext()) {
builder.append(iterator.nextLine());
}
} catch (IOException e) {
throw new JSONClientException("Error in sendGet method due to : " + e.getMessage(), e);
}
if (logger.isDebugEnabled()) {
logger.debug("Status code : " + response.getStatusLine().getStatusCode());
logger.debug("Server response : " + builder.toString());
}
return new DockerResponse(response.getStatusLine().getStatusCode(), builder.toString());
}
示例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("\\|");
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();
}
}
示例4: 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();
}
}
示例5: consumeAsString
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static String consumeAsString ( InputStream response, int maxLines ) {
StringWriter logwriter = new StringWriter();
try {
LineIterator itr = IOUtils.lineIterator( response, "UTF-8" );
int numLines = 0;
while (itr.hasNext() && numLines < maxLines) {
String line = itr.next();
logwriter.write( line + (itr.hasNext() ? "\n" : "") );
numLines++;
System.out.println( line );
// logger.info( line);
// LOG.info("line: " + line);
}
while (itr.hasNext())
itr.next();
// response.close();
} catch (Exception e) {
logger.error( "Failed to close: {}",
CSAP.getCsapFilteredStackTrace( e ) );
return "Failed";
} finally {
IOUtils.closeQuietly( response );
}
return logwriter.toString();
}
示例6: createTCPProxy
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private void createTCPProxy() {
try {
final String cleanCommand = String.format("sudo docker ps -a | grep 'hours ago' | awk '{print $1}' | xargs --no-run-if-empty sudo docker rm",
containerName,
this.targetHost,
this.targetPort,
sourceIPs,
ImageRegistry.get().tcpProxy());
LOGGER.info("Establishing SSH shell");
ssh = SshUtil.getInstance()
.createSshSession(TestConfiguration.proxyHostUsername(), getProxyHost());
ssh.connect();
LOGGER.debug("Connected to ssh console");
final ChannelExec cleanChannel = (ChannelExec) ssh.openChannel("exec");
cleanChannel.setPty(true);
cleanChannel.setCommand(cleanCommand);
cleanChannel.setInputStream(null);
cleanChannel.setOutputStream(System.err);
LOGGER.debug("Executing command: '{}'", cleanCommand);
cleanChannel.connect();
cleanChannel.disconnect();
final String command = String.format("sudo docker run -it --name %s --net=host --rm -e AB_OFF=true -e TARGET_HOST=%s -e TARGET_PORT=%s -e TARGET_VIA=%s %s",
containerName,
this.targetHost,
this.targetPort,
sourceIPs,
ImageRegistry.get().tcpProxy());
LOGGER.info("Establishing SSH shell");
ssh = SshUtil.getInstance()
.createSshSession(TestConfiguration.proxyHostUsername(), getProxyHost());
ssh.connect();
LOGGER.debug("Connected to ssh console");
final ChannelExec channel = (ChannelExec) ssh.openChannel("exec");
channel.setPty(true);
channel.setCommand(command);
channel.setInputStream(null);
channel.setOutputStream(System.err);
LOGGER.debug("Executing command: '{}'", command);
channel.connect();
final LineIterator li = IOUtils.lineIterator(new InputStreamReader(channel.getInputStream()));
final Pattern portLine = Pattern.compile(".*Listening on port ([0-9]*).*$");
listenPort = 0;
while (li.hasNext()) {
final String line = li.next();
LOGGER.trace("Shell line: {}", line);
final Matcher m = portLine.matcher(line);
if (m.matches()) {
listenPort = Integer.parseInt(m.group(1));
LOGGER.info("Connection listening on port {}", listenPort);
break;
}
}
channel.disconnect();
} catch (final JSchException | IOException e) {
LOGGER.debug("Error in creating SSH connection to proxy host", e);
throw new IllegalStateException("Cannot open SSH connection", e);
}
}
示例7: 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;
}
示例8: 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);
}
}
}
示例9: loadData
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private void loadData() {
File f = new File(getClass().getClassLoader().getResource(FILE).getFile());
try {
LineIterator i = FileUtils.lineIterator(f);
String[] header = null;
while (i.hasNext()) {
String[] cols = i.next().split("\t");
if (cols[0].equals("word")) {
for (int c = 1; c < cols.length; c++)
this.data.put(cols[c], new HashMap<String, Integer>());
header = cols;
} else {
String w = cols[0].toLowerCase();
for (int c = 1; c < cols.length; c++) {
if (cols[c].length() > 0)
this.data.get(header[c]).put(w, Integer.parseInt(cols[c]));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: loadData
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private void loadData() {
File f = new File(getClass().getClassLoader().getResource(FILE).getFile());
try {
LineIterator i = FileUtils.lineIterator(f);
while (i.hasNext()) {
String[] cols = i.next().split("\t");
if (!cols[0].equals("Word")) {
String w = cols[0].toLowerCase();
Double s = Double.parseDouble(cols[2]);
this.data.put(w, s);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: setWeights
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public void setWeights(String fileName) {
File f = new File(fileName);
try {
LineIterator i = FileUtils.lineIterator(f);
List<Double> weights = new ArrayList<Double>();
while (i.hasNext()) {
String line = i.next().trim();
if (line.length() > 0)
weights.add(Double.parseDouble(line));
}
this.weights = new double[weights.size()];
for (int j = 0; j < weights.size(); j++)
this.weights[j] = weights.get(j);
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: parseRecords
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private void parseRecords(InputStream stream) throws IOException {
LineIterator it = IOUtils.lineIterator(buffer(stream), IabFile.CHARSET);
while (it.hasNext()) {
String record = StringUtils.trimToNull(it.nextLine());
if (record != null) {
if (isCidrNotation(record)) {
cidrAddresses.add(subnetInfo(record));
} else {
plainAddresses.add(record);
}
}
}
}
示例13: loadFromDb
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private static void loadFromDb(ArrayTable<Integer, Character, List<Person>> personsTable) throws IOException {
long start = System.currentTimeMillis();
File dbFile = new File(Config.DB_FILE_NAME);
LineIterator it = FileUtils.lineIterator(dbFile, "UTF-8");
while(it.hasNext()) {
String line = it.next();
Person person = parseStringTokenizer(line);
char fc = person.name.charAt(0);
List<Person> persons = personsTable.get(person.age, fc);
if(persons == null) {
persons = new ArrayList<>();
personsTable.put(person.age, person.name.charAt(0), persons);
}
persons.add(person);
}
System.out.println("load data elapsed time : " + (System.currentTimeMillis() - start));
}
示例14: splitSentences
import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Override
public List<String> splitSentences(String text, String language_code) throws Exception {
LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200)));
List<String> sentences = new ArrayList<String>();
if(Properties.onedocperline()){
LineIterator liter = new LineIterator(new StringReader(text));
for(String line; (line = liter.hasNext() ? liter.next() : null) != null;)
split_and_add_sentences(line, sentences);
}else{
split_and_add_sentences(text, sentences);
}
LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200), sentences.size()));
return sentences;
}
示例15: 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
}
}