List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:io.github.bunnyblue.droidfix.classcomputer.proguard.MappingMapper.java
public void produce(String path) { try {/* ww w .j av a 2 s.c o m*/ Collection<String> lines = FileUtils.readLines(new File(path)); for (String string : lines) {//android.support.design.internal.NavigationMenuPresenter -> android.support.design.internal.b: if (string.contains(" -> ") && string.endsWith(":")) { String originClass = string.substring(0, string.indexOf(" ")).replaceAll(" ", ""); String proguardClass = string.substring(string.lastIndexOf(" "), string.length() - 1) .replaceAll(" ", ""); hashtable.put(proguardClass, originClass); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.haulmont.ext.core.app.loadClient.LoadClientServiceBean.java
@Override public void loadFromFile(File file) throws IOException { /* InputStreamReader inputStream = new FileReader(path); BufferedReader bufferedReader;//from w w w . j a v a 2 s.c o m bufferedReader = new BufferedReader(inputStream); String line = ""; List<String[]> lines = new ArrayList<String[]>(); while ((line = bufferedReader.readLine()) != null) { lines.add(line.split(";")); } */ List<String> lines = FileUtils.readLines(file); List<String[]> splitLines = new ArrayList<String[]>(); for (String l : lines) { splitLines.add(l.split(";")); } createSuperTransaction(splitLines); }
From source file:com.gargoylesoftware.htmlunit.NotYetImplementedTest.java
private void process(final File dir) throws IOException { for (final File file : dir.listFiles()) { final String fileName = file.getName(); if (file.isDirectory() && !"huge".equals(fileName) && !".svn".equals(fileName)) { process(file);/*from w w w .ja v a 2 s .co m*/ } else { if (fileName.endsWith(".java") && !"SimpleWebTestCase.java".equals(fileName) && !"NotYetImplementedTest.java".equals(fileName) && !"CodeStyleTest.java".equals(fileName)) { final List<String> lines = FileUtils.readLines(file); final String relativePath = file.getAbsolutePath() .substring(new File(".").getAbsolutePath().length() - 1).replace('\\', '/'); process(lines, relativePath); } } } }
From source file:admincommands.Raw.java
@Override public void execute(Player admin, String... params) { if (params.length != 1) { PacketSendUtility.sendMessage(admin, "Usage: //raw [name]"); return;/*from w ww . j ava2 s. co m*/ } File file = new File(ROOT, params[0] + ".txt"); if (!file.exists() || !file.canRead()) { PacketSendUtility.sendMessage(admin, "Wrong file selected."); return; } try { List<String> lines = FileUtils.readLines(file); SM_CUSTOM_PACKET packet = null; PacketSendUtility.sendMessage(admin, "lines " + lines.size()); boolean init = false; for (int r = 0; r < lines.size(); r++) { String row = lines.get(r); String[] tokens = row.substring(0, 48).trim().split(" "); int len = tokens.length; for (int i = 0; i < len; i++) { if (!init) { if (i == 1) { packet = new SM_CUSTOM_PACKET(Integer.decode("0x" + tokens[i] + tokens[i - 1])); init = true; } } else if (r > 0 || i > 4) { packet.addElement(PacketElementType.C, "0x" + tokens[i]); } } } if (packet != null) { PacketSendUtility.sendMessage(admin, "Packet send.."); PacketSendUtility.sendPacket(admin, packet); } } catch (Exception e) { PacketSendUtility.sendMessage(admin, "An error has occurred."); logger.warn("IO Error.", e); } }
From source file:com.sangupta.clitools.file.Trim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.strip(line, null); contents.set(index, line);/* w w w.ja v a 2s .c o m*/ } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:com.sangupta.clitools.file.RightTrim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.stripEnd(line, null); contents.set(index, line);// w w w . j a v a 2 s . c o m } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " right-trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:com.sangupta.clitools.file.LeftTrim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.stripStart(line, null); contents.set(index, line);// www . j av a 2 s . c o m } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " left-trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromcpr34200CSV.java
private void generateAdministrationData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr34200.csv")); boolean first = true; List<String> lines = FileUtils.readLines(file); for (String line : lines) { if (first) { // first row is column metadata first = false;//from www . java2 s. c o m continue; } String[] splits = line.split(";"); String recnum = splits[0]; String sygehus = splits[1]; String afdeling = splits[2]; String type = splits[3]; String cpr = splits[4]; String idate = splits[5]; String udate = splits[6]; String itime = splits[7]; if (itime.length() == 0) { itime = "0"; } String utime = splits[8]; if (utime.length() == 0) { utime = "0"; } StringBuffer sql = new StringBuffer(); sql.append( "INSERT INTO T_ADM (V_RECNUM, C_SGH, C_AFD, V_CPR, D_INDDTO,D_UDDTO,V_INDTIME,V_UDTIME, C_PATTYPE) VALUES ("); sql.append(recnum); sql.append(", '"); sql.append(sygehus); sql.append("', '"); sql.append(afdeling); sql.append("', '"); sql.append(cpr); sql.append("', '"); sql.append(idate); sql.append("', '"); sql.append(udate); sql.append("', "); sql.append(itime); sql.append(", "); sql.append(utime); sql.append(", "); sql.append(type); sql.append(");"); System.out.println(sql.toString()); } }
From source file:com.gargoylesoftware.htmlunit.ExternalTest.java
/** * Tests that POM dependencies are the latest. * * Currently it is configured to check every week. * * @throws Exception if an error occurs/*from w w w . j av a 2 s . co m*/ */ @Test public void pom() throws Exception { if (isDifferentWeek()) { final List<String> lines = FileUtils.readLines(new File("pom.xml")); for (int i = 0; i < lines.size(); i++) { final String line = lines.get(i); if (line.contains("artifactId") && !line.contains(">htmlunit<")) { final String artifactId = getValue(line); final String groupId = getValue(lines.get(i - 1)); if (!lines.get(i + 1).contains("</exclusion>")) { final String version = getValue(lines.get(i + 1)); assertVersion(groupId, artifactId, version); } } } assertVersion("org.sonatype.oss", "oss-parent", "9"); assertChromeDriver("2.20"); } }
From source file:fr.certu.chouette.command.CommandParser.java
public static List<CommandArgument> parseFile(String filename) throws Exception { File f = new File(filename); List<String> lines = FileUtils.readLines(f); List<CommandArgument> commands = new ArrayList<CommandArgument>(); int linenumber = 1; for (int i = 0; i < lines.size(); i++) { String line = lines.get(i).trim(); if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) break; if (!line.isEmpty() && !line.startsWith("#")) { int number = linenumber++; while (line.endsWith("\\")) { line = line.substring(0, line.length() - 1); i++;//w w w. ja v a 2 s . c o m if (i < lines.size()) line += lines.get(i).trim(); } CommandArgument command = parseLine(number, line); if (command != null) { if (command.getName().equalsIgnoreCase("include")) { } else { commands.add(command); } } } } return commands; }