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


Java LineIterator類代碼示例

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

示例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;
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:20,代碼來源:CollectionManagementService.java

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

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

示例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());

    }
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:30,代碼來源:JSONClient.java

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

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

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

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

示例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;

	}
 
開發者ID:pkiraly,項目名稱:metadata-qa-marc,代碼行數:20,代碼來源:CodeFileReader.java

示例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;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:AfnemerindicatieConversie.java

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

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

示例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();
	}
}
 
開發者ID:UKPLab,項目名稱:ijcnlp2017-cmaps,代碼行數:24,代碼來源:MRCFeatures.java

示例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();
	}
}
 
開發者ID:UKPLab,項目名稱:ijcnlp2017-cmaps,代碼行數:17,代碼來源:ConcFeatures.java


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