当前位置: 首页>>代码示例>>Java>>正文


Java LineIterator.next方法代码示例

本文整理汇总了Java中org.apache.commons.io.LineIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java LineIterator.next方法的具体用法?Java LineIterator.next怎么用?Java LineIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.LineIterator的用法示例。


在下文中一共展示了LineIterator.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:30,代码来源:Docker_Java.java

示例2: 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);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:64,代码来源:ProxiedConnectionManager.java

示例3: 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));
}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:19,代码来源:MyPersonCaclByArrayTable.java

示例4: 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;
}
 
开发者ID:tudarmstadt-lt,项目名称:topicrawler,代码行数:17,代码来源:LtSegProvider.java

示例5: loadTable

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static Table<String, String, Long> loadTable(InputStream stream)
        throws IOException
{
    Table<String, String, Long> result = TreeBasedTable.create();

    LineIterator lineIterator = IOUtils.lineIterator(stream, "utf-8");
    while (lineIterator.hasNext()) {
        String line = lineIterator.next();

        System.out.println(line);

        String[] split = line.split("\t");
        String language = split[0];
        String license = split[1];
        Long documents = Long.valueOf(split[2]);
        Long tokens = Long.valueOf(split[3]);

        result.put(language, "docs " + license, documents);
        result.put(language, "tokens " + license, tokens);
    }

    return result;
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:24,代码来源:StatisticsTableCreator.java

示例6: loadCorpusToRankedVocabulary

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static LinkedHashMap<String, Integer> loadCorpusToRankedVocabulary(InputStream corpus)
        throws IOException
{
    LinkedHashMap<String, Integer> result = new LinkedHashMap<>();

    LineIterator lineIterator = IOUtils.lineIterator(corpus, "utf-8");
    int counter = 0;
    while (lineIterator.hasNext()) {
        String line = lineIterator.next();

        String word = line.split("\\s+")[0];

        result.put(word, counter);
        counter++;
    }

    return result;
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:19,代码来源:TopNWordsCorrelation.java

示例7: parseIncludeDescriptors

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private List<ActionDescriptor> parseIncludeDescriptors(Script script, Map<String, String> definitions,
		List<Script> includes, ResourceResolver resolver) throws ExecutionException {
	final List<ActionDescriptor> descriptors = new LinkedList<>();
	LineIterator lineIterator = IOUtils.lineIterator(new StringReader(script.getData()));

	while (lineIterator.hasNext()) {
		String line = lineIterator.next();
		if (ScriptUtils.isAction(line)) {
			final String command = ScriptUtils.parseCommand(line, definitions);
			final ActionDescriptor descriptor = actionFactory.evaluate(command);
			final Action action = descriptor.getAction();

			descriptors.add(descriptor);

			if (action instanceof DefinitionProvider) {
				definitions.putAll(((DefinitionProvider) action).provideDefinitions(definitions));
			} else if (action instanceof ScriptProvider) {
				getIncludes(definitions, includes, resolver, descriptors, (ScriptProvider) action);
			}
		}
	}
	return descriptors;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:24,代码来源:ScriptManagerImpl.java

示例8: defaultBuildCommand

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
@Override
public void defaultBuildCommand(String eclipseProjectName, String dockerBuildContext) {
    File baseDir = new File(dockerBuildContext);
    InputStream response = dockerClient.buildImageCmd(baseDir).exec();
    StringWriter logwriter = new StringWriter();
    messageConsole.getDockerConsoleOut().println(">>> Building " + dockerBuildContext + "/Dockerfile with default options");
    messageConsole.getDockerConsoleOut().println("");

    try {
        messageConsole.getDockerConsoleOut().flush();
        LineIterator itr = IOUtils.lineIterator(response, "UTF-8");
        while (itr.hasNext()) {
            String line = itr.next();
            logwriter.write(line);
            messageConsole.getDockerConsoleOut().println(line);
            messageConsole.getDockerConsoleOut().flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(response);
    }

    messageConsole.getDockerConsoleOut().println("");
    messageConsole.getDockerConsoleOut().println("<<< Build ended");
}
 
开发者ID:domeide,项目名称:doclipser,代码行数:27,代码来源:DockerClientJavaApi.java

示例9: main

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	LineIterator goldIt = FileUtils.lineIterator(new File("/home/seid/Desktop/tmp/engner/gold_testb.tsv"));
	LineIterator predIt = FileUtils.lineIterator(new File("/home/seid/Desktop/tmp/engner/pred.tsv"));
	boolean flag = false;
	OutputStream os = new FileOutputStream(new File("/home/seid/Desktop/tmp/engner/eval.tsv"));

	while (goldIt.hasNext()) {

		String goldLine = goldIt.next();
		String predLine = predIt.next();
		if (goldLine.isEmpty() && !flag) {
			flag = true;
			IOUtils.write("\n", os, "UTF8");
		} else if (goldLine.isEmpty()) {
			continue;
		} else {
			IOUtils.write(goldLine.replace("\t", " ") + " " + predLine.split("\t")[1] + "\n", os, "UTF8");
			flag = false;
		}

	}

}
 
开发者ID:tudarmstadt-lt,项目名称:GermaNER,代码行数:24,代码来源:MergeResultToGold.java

示例10: isTabSepFileFormatCorrect

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
 * Check if a TAB-Sep training file is in correct format before importing
 */
private boolean isTabSepFileFormatCorrect(File aFile)
{
    try {
        LineIterator it = new LineIterator(new FileReader(aFile));
        while (it.hasNext()) {
            String line = it.next();
            if (line.trim().length() == 0) {
                continue;
            }
            if (line.split("\t").length != 2) {
                return false;
            }
        }
    }
    catch (Exception e) {
        return false;
    }
    return true;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:MiraAutomationServiceImpl.java

示例11: collectResponse

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public static String collectResponse(InputStream response) {
    StringWriter logwriter = new StringWriter();

    try {
        LineIterator itr = IOUtils.lineIterator(response, "UTF-8");

        while (itr.hasNext()) {
            String line = (String) itr.next();
            logwriter.write(line + (itr.hasNext() ? "\n" : ""));
        }
        response.close();

        return logwriter.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(response);
    }
}
 
开发者ID:mesos,项目名称:logstash,代码行数:20,代码来源:ResponseCollector.java

示例12: readLongsFromFile

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
private Set<Long> readLongsFromFile(File fileWithLongs) {
    Set<Long> resultSet = new HashSet<Long>();
    try {
        LineIterator lineIterator = new LineIterator(new FileReader(fileWithLongs));
        while (lineIterator.hasNext()) {
            String line = lineIterator.next();
            resultSet.add(Long.parseLong(line));
        }
    } catch (IOException e) {
        log.fatal("Unable to read from file '" 
                + fileWithLongs.getAbsolutePath() 
                + "'. Returns set of size " + resultSet.size());
    }
    
    return resultSet;
}
 
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:17,代码来源:TestIndexRequestServer.java

示例13: 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

示例14: getLogOfContainer

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
public String getLogOfContainer(String instanceId, String containerId) {
  try {
    DockerClient dockerClient = getDockerClientForInstance(instanceId);
    ClientResponse response =
        dockerClient.logContainerCmd(containerId).withStdOut().withStdErr().exec();

    StringBuilder builder = new StringBuilder();

    try {
      LineIterator itr = IOUtils.lineIterator(response.getEntityInputStream(), "UTF-8"); //$NON-NLS-1$
      while (itr.hasNext()) {
        String line = itr.next();
        builder.append(line);
        builder.append(NL);
      }
    } finally {
      IOUtils.closeQuietly(response.getEntityInputStream());
    }

    return builder.toString();
  } catch (DockerException | IOException e) {
    console.exception(e, "Cannot get Docker log"); //$NON-NLS-1$
  }

  return "no log available"; //$NON-NLS-1$
}
 
开发者ID:tuhrig,项目名称:DeployMan,代码行数:27,代码来源:DockerRemoteClient.java

示例15: responseAsString

import org.apache.commons.io.LineIterator; //导入方法依赖的package包/类
/**
 * Accepts an InputStream as a parameter, converts it into a String
 * and returns that String.
 * @param response
 * @return String
 */
protected String responseAsString(InputStream response) {
	StringWriter logwriter = new StringWriter();
	try {
		LineIterator itr = IOUtils.lineIterator(
				response, "UTF-8");
		while (itr.hasNext()) {
			String line = itr.next();
			logwriter.write(line + (itr.hasNext() ? "\n" : ""));
			LOG.info("line: " + line);
		}
		return logwriter.toString();
	}
	catch (IOException e) {
		throw new RuntimeException(e);
	}
	finally {
		IOUtils.closeQuietly(response);
	}
}
 
开发者ID:DePaul2015SEStudioTeam1,项目名称:agent,代码行数:26,代码来源:LocalDockerService.java


注:本文中的org.apache.commons.io.LineIterator.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。