本文整理匯總了Java中org.apache.commons.io.LineIterator類的典型用法代碼示例。如果您正苦於以下問題:Java LineIterator類的具體用法?Java LineIterator怎麽用?Java LineIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LineIterator類屬於org.apache.commons.io包,在下文中一共展示了LineIterator類的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();
}
}
示例2: listRuntimeDependencies
import org.apache.commons.io.LineIterator; //導入依賴的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.LineIterator; //導入依賴的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: 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);
}
}
示例5: 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());
}
示例6: 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();
}
}
示例7: 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();
}
示例8: testAck
import org.apache.commons.io.LineIterator; //導入依賴的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();
}
}
示例9: 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);
}
}
示例10: 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;
}
示例11: converteerPersafnemerindicatieTabel
import org.apache.commons.io.LineIterator; //導入依賴的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;
}
示例12: 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);
}
}
}
示例13: converteerHisPersafnemerindicatieTabel
import org.apache.commons.io.LineIterator; //導入依賴的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);
}
示例14: 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();
}
}
示例15: 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();
}
}