List of usage examples for org.apache.commons.io FileUtils lineIterator
public static LineIterator lineIterator(File file) throws IOException
File
using the default encoding for the VM. From source file:com.senseidb.search.node.inmemory.InMemoryIndexPerfEval.java
public static void main(String[] args) throws Exception { final InMemorySenseiService memorySenseiService = InMemorySenseiService.valueOf( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI())); final List<JSONObject> docs = new ArrayList<JSONObject>(15000); LineIterator lineIterator = FileUtils.lineIterator( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI())); int i = 0;/*from w ww . ja v a2s .c o m*/ while (lineIterator.hasNext() && i < 100) { String car = lineIterator.next(); if (car != null && car.contains("{")) docs.add(new JSONObject(car)); i++; } Thread[] threads = new Thread[10]; for (int k = 0; k < threads.length; k++) { threads[k] = new Thread(new Runnable() { public void run() { long time = System.currentTimeMillis(); //System.out.println("Start thread"); for (int j = 0; j < 1000; j++) { //System.out.println("Send request"); memorySenseiService.doQuery(getRequest(), docs); } System.out.println("time = " + (System.currentTimeMillis() - time)); } }); threads[k].start(); } Thread.sleep(500000); }
From source file:com.github.xbn.examples.regexutil.non_xbn.MatchEachWordInEveryLine.java
public static final void main(String[] as_1RqdTxtFilePath) { Iterator<String> lineItr = null; try {// w ww .j av a 2 s . com lineItr = FileUtils.lineIterator(new File(as_1RqdTxtFilePath[0])); //Throws npx if null } catch (IOException iox) { throw new RuntimeException("Attempting to open \"" + as_1RqdTxtFilePath[0] + "\"", iox); } catch (RuntimeException rx) { throw new RuntimeException("One required parameter: The path to the text file.", rx); } //Dummy search string (""), so it can be reused (reset) Matcher mWord = Pattern.compile("\\b\\w+\\b").matcher(""); while (lineItr.hasNext()) { String sLine = lineItr.next(); mWord.reset(sLine); while (mWord.find()) { System.out.println(mWord.group()); } } }
From source file:com.github.xbn.examples.regexutil.non_xbn.BetweenLineMarkersButSkipFirstXmpl.java
public static final void main(String[] as_1RqdTxtFilePath) { Iterator<String> lineItr = null; try {//from w w w . ja va2 s . co m lineItr = FileUtils.lineIterator(new File(as_1RqdTxtFilePath[0])); //Throws npx if null } catch (IOException iox) { throw new RuntimeException("Attempting to open \"" + as_1RqdTxtFilePath[0] + "\"", iox); } catch (RuntimeException rx) { throw new RuntimeException("One required parameter: The path to the text file.", rx); } String LINE_SEP = System.getProperty("line.separator", "\n"); ArrayList<String> alsItems = new ArrayList<String>(); boolean bStartMark = false; boolean bLine1Skipped = false; StringBuilder sdCurrentItem = new StringBuilder(); while (lineItr.hasNext()) { String sLine = lineItr.next().trim(); if (!bStartMark) { if (sLine.startsWith(".START_SEQUENCE")) { bStartMark = true; continue; } throw new IllegalStateException("Start mark not found."); } if (!bLine1Skipped) { bLine1Skipped = true; continue; } else if (!sLine.equals(".END_SEQUENCE")) { sdCurrentItem.append(sLine).append(LINE_SEP); } else { alsItems.add(sdCurrentItem.toString()); sdCurrentItem.setLength(0); bStartMark = false; bLine1Skipped = false; continue; } } for (String s : alsItems) { System.out.println("----------"); System.out.print(s); } }
From source file:com.github.xbn.examples.io.non_xbn.DelimitWordsInATextFile.java
public static final void main(String[] as_1RqdPathToInput) { //Read command-line String sSrc = null;/*from ww w . ja va 2s . com*/ try { sSrc = as_1RqdPathToInput[0]; } catch (IndexOutOfBoundsException ibx) { System.out.println("Missing one-and-only required parameter: The full path to input file."); return; } //Open input file File fSrc = new File(sSrc); Iterator<String> lineItr = null; try { lineItr = FileUtils.lineIterator(fSrc); } catch (IOException iox) { System.out.println("Cannot open \"" + sSrc + "\". " + iox); return; } int i = 0; while (lineItr.hasNext()) { i++; String as[] = lineItr.next().split(" "); System.out.println("Line " + i + ": " + Arrays.toString(as)); } }
From source file:com.github.xbn.examples.io.non_xbn.ReadInActiveAccountsFromFile.java
public static final void main(String[] rqdInputPathInStrArray) { //Read command-line String sSrc = null;// www.j a v a 2 s.co m try { sSrc = rqdInputPathInStrArray[0]; } catch (IndexOutOfBoundsException ibx) { System.out.println("Missing one-and-only required parameter: The full path to Java source-code file."); return; } //Open input file File inputFile = new File(sSrc); Iterator<String> lineItr = null; try { lineItr = FileUtils.lineIterator(inputFile); } catch (IOException iox) { System.out.println("Cannot open \"" + sSrc + "\". " + iox); return; } while (lineItr.hasNext()) { String line = lineItr.next(); String[] userPassIsActive = line.split(" "); String username = userPassIsActive[0]; String password = userPassIsActive[1]; boolean isActive = Boolean.parseBoolean(userPassIsActive[2]); System.out.println("username=" + username + ", password=" + password + ", isActive=" + isActive + ""); } }
From source file:com.github.xbn.examples.io.non_xbn.SudokuTxtFileDataXmpl.java
public static final void main(String[] as_1RqdPathToInput) { //Read command-line String sSrc = null;/*from ww w .ja v a 2 s.co m*/ try { sSrc = as_1RqdPathToInput[0]; } catch (IndexOutOfBoundsException ibx) { System.out.println("Missing one-and-only required parameter: The full path to Java source-code file."); return; } //Open input file File fSrc = new File(sSrc); Iterator<String> li = null; try { li = FileUtils.lineIterator(fSrc); } catch (IOException iox) { System.out.println("Cannot open \"" + sSrc + "\". " + iox); return; } String[] asNineElementsRow1 = getAndOutputDataRow(li.next()); String[] asNineElementsRow2 = getAndOutputDataRow(li.next()); String[] asNineElementsRow3 = getAndOutputDataRow(li.next()); li.next(); //blank line System.out.println("-----------------------"); String[] asNineElementsRow4 = getAndOutputDataRow(li.next()); String[] asNineElementsRow5 = getAndOutputDataRow(li.next()); String[] asNineElementsRow6 = getAndOutputDataRow(li.next()); li.next(); //blank line System.out.println("-----------------------"); String[] asNineElementsRow7 = getAndOutputDataRow(li.next()); String[] asNineElementsRow8 = getAndOutputDataRow(li.next()); String[] asNineElementsRow9 = getAndOutputDataRow(li.next()); }
From source file:com.github.aliteralmind.codelet.examples.non_xbn.PrintJDBlocksStartStopLineNumsXmpl.java
/** <p>The main function.</p> *///from w w w. j a v a2 s. c o m public static final void main(String[] as_1RqdJavaSourcePath) { //Read command-line parameter String sJPath = null; try { sJPath = as_1RqdJavaSourcePath[0]; } catch (ArrayIndexOutOfBoundsException aibx) { throw new NullPointerException( "Missing one-and-only required parameter: Path to java source-code file."); } System.out.println("Java source: " + sJPath); //Establish line-iterator Iterator<String> lineItr = null; try { lineItr = FileUtils.lineIterator(new File(sJPath)); //Throws npx if null } catch (IOException iox) { throw new RTIOException("PrintJDBlocksStartStopLinesXmpl", iox); } Pattern pTrmdJDBlockStart = Pattern.compile("^[\\t ]*/\\*\\*"); String sDD = ".."; int lineNum = 1; boolean bInJDBlock = false; while (lineItr.hasNext()) { String sLn = lineItr.next(); if (!bInJDBlock) { if (pTrmdJDBlockStart.matcher(sLn).matches()) { bInJDBlock = true; System.out.print(lineNum + sDD); } } else if (sLn.indexOf("*/") != -1) { bInJDBlock = false; System.out.println(lineNum); } lineNum++; } if (bInJDBlock) { throw new IllegalStateException("Reach end of file. JavaDoc not closed."); } }
From source file:data_gen.Data_gen.java
public static void main(String[] args) throws FileNotFoundException, IOException { long startTime = System.nanoTime(); if (args.length < 2) { System.out.println("Usage:"); System.out.println(/* www . ja v a 2 s . c o m*/ "java -jar \"jarfile\" [Directory of text source folder] [Dierctory of configration file]" + "\n"); System.exit(0); } String Dir = args[0]; // get text source dir from user String config_dir = args[1]; File folder = new File(Dir); if (folder.isDirectory() == false) { System.out.println("Text souce folder is not a Directory." + "\n"); System.exit(0); } if (!config_dir.endsWith(".properties") && !config_dir.endsWith(".PROPERTIES")) { System.out.println("\n" + "There was error parsing dataset parameters from configuration file, make sure you have the 4 parameters specified and the right type of file" + "\n"); System.exit(0); } listOfFiles = folder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".txt"); } }); if (listOfFiles.length == 0) { System.out.println("Text source folder is empty ! Have at least one .txt file there" + "\n"); System.exit(0); } System.out.println("\n"); Parse_Document_values(config_dir);// parse config file to get class attribute values document_size = Docments_Total_size / documents_count; // to get each document size max = (long) ((double) document_size * 1.8); min = (long) ((double) document_size * 0.2); schema_fields = Parse_Document_fields(config_dir); try { LineIterator it = FileUtils.lineIterator(listOfFiles[0]); while (it.hasNext()) { tx.add(it.nextLine()); } } catch (NullPointerException | FileNotFoundException e) { System.out.println("The text source file could not be found." + "\n"); System.exit(0); } new File(output_dir).mkdir(); //////////////////////////////////////////////////////////////// build json or .dat //////////////////////////////////////////////////////////////////// if (Default_DataSet_name.endsWith(".json")) { Build_json_file(config_dir, startTime); } if (Default_DataSet_name.endsWith(".dat")) { Build_dat_file(config_dir, startTime); } generate_xml(); generate_field_map(); }
From source file:com.el.wordament.NodeLoader.java
public static Node init() throws IOException { LineIterator iterator = FileUtils.lineIterator(new File("src/main/resources/dict.txt")); Node root = new Node(); root.setWord(false);/*www . j a v a 2 s. c om*/ while (iterator.hasNext()) { String line = iterator.next().toLowerCase().trim(); createNodes(line, root, 0).setWord(true); } return root; }
From source file:automaticdatabaseupdate.FileHandler.java
/** * * @param strFilePath - path of given file e.g. "D:\\EGYETEM\\Szakdolgozat\\Mernoki_tervezes\\update files\\sr28upd\\ADD_NUTR.txt" * @param strFileType - type of the given file e.g. AddFood * @param TList - list to fill with data e.g. List<FileFoodStruct> ListFFS *//*from ww w . ja va2s . c o m*/ public static <T> void readFile(String strFilePath, List<T> TList, String strFileType) { TList.clear(); try { File file = FileUtils.getFile(strFilePath); LineIterator iter = FileUtils.lineIterator(file); while (iter.hasNext()) { String strLine = iter.next(); switch (strFileType) { case "ADD_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "ADD_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "ADD_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(1)); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "LOG_FILE": { ArrayList<String> strList = ParseLogFile(strLine); TraceMessage Object = new TraceMessage(strList.get(0), strList.get(1)); TList.add((T) Object); break; } } } //System.out.println( "Total line: " + moduleCounter ); iter.close(); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } }