本文整理汇总了Java中org.apache.commons.io.IOUtils.lineIterator方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.lineIterator方法的具体用法?Java IOUtils.lineIterator怎么用?Java IOUtils.lineIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.lineIterator方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectWhetherAppIsFramework
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public boolean detectWhetherAppIsFramework(File appDir)
throws AndrolibException {
File publicXml = new File(appDir, "res/values/public.xml");
if (!publicXml.exists()) {
return false;
}
Iterator<String> it;
try {
it = IOUtils.lineIterator(new FileReader(new File(appDir,
"res/values/public.xml")));
} catch (FileNotFoundException ex) {
throw new AndrolibException(
"Could not detect whether app is framework one", ex);
}
it.next();
it.next();
return it.next().contains("0x01");
}
示例2: listRuntimeDependencies
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
protected List<String> listRuntimeDependencies(String collectionName) throws IOException, SolrServerException {
ModifiableSolrParams params = new ModifiableSolrParams().set("file",RUNTIME_LIB_FILE_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/file");
request.setResponseParser(new InputStreamResponseParser("json"));
NamedList o = client.request(request, collectionName);
LineIterator it = IOUtils.lineIterator((InputStream) o.get("stream"), "utf-8");
List<String> returnValues = Streams.stream(it).collect(Collectors.toList());
//if file not exists (a little hacky..)
if(returnValues.size() == 1 && returnValues.get(0).startsWith("{\"responseHeader\":{\"status\":404")) {
logger.warn("Release does not yet contain rumtimelib configuration file. Runtimelibs have to be installed manually.");
return Collections.emptyList();
};
return returnValues;
}
示例3: testMaxLineLengthwithAck
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Test that line above MaxLineLength are discarded
*
* @throws InterruptedException
* @throws IOException
*/
@Test
public void testMaxLineLengthwithAck() throws InterruptedException, IOException {
String encoding = "UTF-8";
String ackEvent = "OK";
String ackErrorEvent = "FAILED: Event exceeds the maximum length (10 chars, including newline)";
startSource(encoding, "true", "1", "10");
Socket netcatSocket = new Socket(localhost, selectedPort);
LineIterator inputLineIterator = IOUtils.lineIterator(netcatSocket.getInputStream(), encoding);
try {
sendEvent(netcatSocket, "123456789", encoding);
Assert.assertArrayEquals("Channel contained our event",
"123456789".getBytes(defaultCharset), getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
sendEvent(netcatSocket, english, encoding);
Assert.assertEquals("Channel does not contain an event", null, getRawFlumeEvent());
Assert.assertEquals("Socket contained the Error Ack", ackErrorEvent, inputLineIterator
.nextLine());
} finally {
netcatSocket.close();
stopSource();
}
}
示例4: loadWords
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private Set<String> loadWords() throws IOException {
Set<String> words = new HashSet<>();
try (Reader r = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(IGNORED_RESOURCE),UTF8)){
Iterator<String> lines = IOUtils.lineIterator(r);
while(lines.hasNext()){
String word = StringUtils.trimToNull(lines.next());
if(word != null){
words.add(word.toLowerCase(Locale.ROOT));
}
}
} catch (NullPointerException e) {
log.warn("Wordlist for ignored adjectives (resource: {}) not present", IGNORED_RESOURCE);
log.debug("EXCEPTION", e);
}
return words;
}
示例5: sendGet
import org.apache.commons.io.IOUtils; //导入方法依赖的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());
}
示例6: consumeAsString
import org.apache.commons.io.IOUtils; //导入方法依赖的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();
}
示例7: testAck
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Test if an ack is sent for every event in the correct encoding
*
* @throws InterruptedException
* @throws IOException
*/
@Test
public void testAck() throws InterruptedException, IOException {
String encoding = "UTF-8";
String ackEvent = "OK";
startSource(encoding, "true", "1", "512");
Socket netcatSocket = new Socket(localhost, selectedPort);
LineIterator inputLineIterator = IOUtils.lineIterator(netcatSocket.getInputStream(), encoding);
try {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
}
} finally {
netcatSocket.close();
stopSource();
}
}
示例8: createTCPProxy
import org.apache.commons.io.IOUtils; //导入方法依赖的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);
}
}
示例9: converteerPersafnemerindicatieTabel
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private long converteerPersafnemerindicatieTabel(final long maxAfnemerindicatieId) throws IOException {
afnemerindicatieDatabaseInteractieStrategy.dumpAfnemerindicatieTabelNaarFile(persafnemerindicatieOudFile);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(persafnemerindicatieNieuwFile))) {
try (InputStream is = new BufferedInputStream(new FileInputStream(persafnemerindicatieOudFile))) {
final LineIterator it = IOUtils.lineIterator(is, StandardCharsets.UTF_8);
converteerAfnemerindicatiebestand(maxAfnemerindicatieId, os, it);
}
}
afnemerindicatieDatabaseInteractieStrategy.vulAfnemerindicatieTabel(persafnemerindicatieNieuwFile);
return maxAfnemerindicatieId;
}
示例10: converteerHisPersafnemerindicatieTabel
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void converteerHisPersafnemerindicatieTabel(final long maxAfnemerindicatieId)
throws IOException {
afnemerindicatieDatabaseInteractieStrategy.dumpHisAfnemerindicatieTabel(hisPersafnemerindicatieOudFile);
final long maxHisAfnemerindicatieId = bepaalMaxId(PersoonAfnemerindicatieHistorie.class).longValue();
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(hisPersafnemerindicatieNieuwFile))) {
try (InputStream is = new BufferedInputStream(new FileInputStream(hisPersafnemerindicatieOudFile))) {
final LineIterator it = IOUtils.lineIterator(is, StandardCharsets.UTF_8);
converteerHisAfnemerindicatiebestand(maxAfnemerindicatieId, maxHisAfnemerindicatieId, os, it);
}
}
afnemerindicatieDatabaseInteractieStrategy.vulHisAfnemerindicatieTabel(hisPersafnemerindicatieNieuwFile);
}
示例11: parseRecords
import org.apache.commons.io.IOUtils; //导入方法依赖的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);
}
}
}
}
示例12: search
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Provides the openSearch description file via /search/description API.
*
* @param res response
* @throws IOException if file description cannot be accessed
*/
@PreAuthorize("hasRole('ROLE_SEARCH')")
@RequestMapping(value = "/description")
public void search(HttpServletResponse res) throws IOException
{
String url = configurationManager.getServerConfiguration().getExternalUrl();
if (url != null && url.endsWith("/"))
{
url = url.substring(0, url.length() - 1);
}
String long_name = configurationManager.getNameConfiguration().getLongName();
String short_name = configurationManager.getNameConfiguration().getShortName();
String contact_mail = configurationManager.getSupportConfiguration().getMail();
InputStream is = ClassLoader.getSystemResourceAsStream(DESCRIPTION_FILE);
if (is == null)
{
throw new IOException("Cannot find \"" + DESCRIPTION_FILE
+ "\" OpenSearch description file.");
}
LineIterator li = IOUtils.lineIterator(is, "UTF-8");
try (ServletOutputStream os = res.getOutputStream())
{
while (li.hasNext())
{
String line = li.next();
// Last line? -> the iterator eats LF
if (li.hasNext())
{
line = line + "\n";
}
line = line.replace("[dhus_server]", url);
if (long_name != null)
{
line = line.replace("[dhus_long_name]", long_name);
}
if (short_name != null)
{
line = line.replace("[dhus_short_name]", short_name);
}
if (contact_mail != null)
{
line = line.replace("[dhus_contact_mail]", contact_mail);
}
os.write(line.getBytes());
}
}
finally
{
IOUtils.closeQuietly(is);
LineIterator.closeQuietly(li);
}
}
示例13: getLineIterator
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static LineIterator getLineIterator(String fileName) throws IOException {
ClassLoader classLoader = CodeFileReader.class.getClassLoader();
return IOUtils.lineIterator(classLoader.getResourceAsStream(fileName), Charset.defaultCharset());
}