List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:com.splunk.shuttl.archiver.model.MovesBucketsTest.java
public void moveBucket_givenDirectoryWithContents_contentShouldBeMoved() throws IOException { String contentsFileName = "contents"; File contents = TUtilsFile.createFileInParent(bucket.getDirectory(), contentsFileName); TUtilsFile.populateFileWithRandomContent(contents); List<String> contentLines = IOUtils.readLines(new FileReader(contents)); Bucket movedBucket = MovesBuckets.moveBucket(bucket, directoryToMoveTo); File movedContents = new File(movedBucket.getDirectory().getAbsolutePath(), contentsFileName); assertTrue(movedContents.exists());// www . j a v a 2s.c o m assertTrue(!contents.exists()); List<String> movedContentLines = IOUtils.readLines(new FileReader(movedContents)); assertEquals(contentLines, movedContentLines); }
From source file:net.sf.reportengine.out.TestHtmlReportOutput.java
@Test public void testUtf8Characters() throws IOException { String OUTPUT_PATH = "target/TestHtmlReportOutputUtf8.html"; HtmlReportOutput testOutput = new HtmlReportOutput(ReportIoUtils.createWriterFromPath(OUTPUT_PATH)); testOutput.open();/*from ww w . j ava2 s . co m*/ testOutput.output("title.ftl", new ParagraphProps("? ? ")); testOutput.output("title.ftl", new ParagraphProps(" ")); testOutput.close(); List<String> lines = IOUtils.readLines(ReportIoUtils.createReaderFromPath(OUTPUT_PATH)); assertEquals(2, lines.size()); assertEquals( "<p style=\"text-align: center; vertical-align: middle\">? ? </p>", lines.get(0)); assertEquals( "<p style=\"text-align: center; vertical-align: middle\"> </p>", lines.get(1)); }
From source file:de.tudarmstadt.ukp.dkpro.tc.svmhmm.writer.SVMHMMDataWriterTest.java
@Test public void testWrite() throws Exception { Set<String> randomFeatureNames = new HashSet<>(); int maxFeatureVectorSize = 100000; for (int i = 0; i < maxFeatureVectorSize; i++) { randomFeatureNames.add(String.valueOf(i)); }// www. jav a 2 s .c o m List<String> allFeatureNames = new ArrayList<>(randomFeatureNames); featureStore = new SparseFeatureStore(); // add 100.000 instances for (int i = 0; i < TESTING_INSTANCES; i++) { Instance instance = new Instance(); instance.setOutcomes("outcome"); // add 10 random features int offset = random.nextInt(maxFeatureVectorSize - TESTING_FEATURES_PER_INSTANCE); List<String> featureNames = allFeatureNames.subList(offset, offset + TESTING_FEATURES_PER_INSTANCE); for (String featureName : featureNames) { instance.addFeature(new Feature(featureName, 1)); } instance.addFeature(new Feature(OriginalTextHolderFeatureExtractor.ORIGINAL_TEXT, "token")); featureStore.addInstance(instance); } SVMHMMDataWriter svmhmmDataWriter = new SVMHMMDataWriter(); System.out.println(featureStore.getNumberOfInstances()); svmhmmDataWriter.write(temporaryFolder.getRoot(), featureStore, false, null, false); List<String> lines = IOUtils .readLines(new FileInputStream(new File(temporaryFolder.getRoot(), "feature-vectors.txt"))); System.out.println(lines.subList(0, 5)); }
From source file:dpcs.AppPackagesList.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public AppPackagesList() { setResizable(false);//ww w . ja v a 2 s . c o m setTitle("App Packages List"); setIconImage(Toolkit.getDefaultToolkit().getImage(AppPackagesList.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 479, 451); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 12, 428, 333); contentPane.add(scrollPane); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages > /sdcard/.allapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.allapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.allapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".allapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } applist = new JList(); applist.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(applist); File file = new File(".allapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(125, 357, 220, 47); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages > /sdcard/.allapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.allapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.allapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".allapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } applist = new JList(); applist.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(applist); File file = new File(".allapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } }
From source file:com.splunk.shuttl.testutil.ShellClassRunner.java
private void printStdOutAndErr() { try {//from w ww . jav a 2s .c o m System.err.println(IOUtils.readLines(runClassProcess.getErrorStream())); System.err.println(IOUtils.readLines(runClassProcess.getInputStream())); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.bluexml.xforms.messages.DefaultMessages.java
private static String[] getPropertiesAsStringArray(String fileName) { String[] lines = null;/*from ww w . j a va 2 s . c o m*/ // get file stream from classPath InputStream in = DefaultMessages.class.getResourceAsStream(fileName); List<?> l = null; try { l = IOUtils.readLines(in); } catch (IOException e) { l = new ArrayList<String>(); System.err.println("Stream for default file " + fileName + " can't be oppened :" + e); } lines = l.toArray(new String[l.size()]); return lines; }
From source file:com.vitesify.languidmpd.streams.MPDStreamProcesser.java
private Collection<String> send_message_and_return_response(Message messageType, Collection<String> args) throws IOException { ow.write(messageType.toString());//from ww w . j av a2s . c o m Collection<String> result = IOUtils.readLines(ir); return result; }
From source file:com.nsano.uat.Imtservlet.java
/** * * @param request/*from ww w . j a v a 2 s . c om*/ * @return * @throws IOException */ private String moneytransfer(HttpServletRequest request) throws IOException, JSONException, NoSuchAlgorithmException { // joined json string String join = ""; JsonElement root = null; JsonElement root2 = null; JsonElement root3 = null; String responseobject = ""; //String nickname="KENDYIPL"; // These represent parameters received over the network String tag = "", apikey = "", refID = "", sender = "", sender_country = "", receiver = "", receiver_msisdn = "", receiver_country = "", amount = "", mno = ""; //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative // Get all parameters, the keys of the parameters are specified List<String> lines = IOUtils.readLines(request.getReader()); // used to format/join incoming JSon string join = StringUtils.join(lines.toArray(), ""); //############################################################################### // instantiate the JSon //Note //The = sign is encoded to \u003d. Hence you need to use disableHtmlEscaping(). //############################################################################### Gson g = new GsonBuilder().disableHtmlEscaping().create(); //Gson g = new Gson(); Map<String, String> expected = new HashMap<>(); try { // parse the JSon string //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative root = new JsonParser().parse(join); tag = root.getAsJsonObject().get("tag").getAsString(); apikey = root.getAsJsonObject().get("apikey").getAsString(); refID = root.getAsJsonObject().get("refID").getAsString(); sender = root.getAsJsonObject().get("sender").getAsString(); sender_country = root.getAsJsonObject().get("sender_country").getAsString(); receiver = root.getAsJsonObject().get("receiver").getAsString(); receiver_msisdn = root.getAsJsonObject().get("receiver_msisdn").getAsString(); receiver_country = root.getAsJsonObject().get("receiver_country").getAsString(); amount = root.getAsJsonObject().get("amount").getAsString(); mno = root.getAsJsonObject().get("mno").getAsString(); } catch (Exception e) { expected.put("command_status", "COMMANDSTATUS_INVALID_PARAMETERS"); String jsonResult = g.toJson(expected); System.out.println(e); return jsonResult; } //check for the presence of all required parameters if (StringUtils.isBlank(tag) || StringUtils.isBlank(apikey) || StringUtils.isBlank(refID) || StringUtils.isBlank(sender) || StringUtils.isBlank(sender_country) || StringUtils.isBlank(receiver) || StringUtils.isBlank(receiver_msisdn) || StringUtils.isBlank(receiver_country) || StringUtils.isBlank(amount) || StringUtils.isBlank(mno)) { //expected.put("username", username); expected.put("status_code", statuscode); expected.put("status_description", Statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } //assign the remit url from properties.config //String processtransaction = airtelbalance.AirtelBalance( nickname, username, password); String processtransaction = cred.sendPOST(); //capture the switch respoinse. System.out.println(processtransaction); //pass the returned json string JsonElement roots = new JsonParser().parse(processtransaction); //JsonElement rootsone = roots.getAsJsonObject(); //exctract a specific json element from the object(status_code) //Double code = roots.getAsJsonObject().get("code").getAsDouble(); Number code = roots.getAsJsonObject().get("code").getAsNumber(); String msg = roots.getAsJsonObject().get("msg").getAsString(); //String data = rootsone.getAsJsonObject().get("error_type").getAsString(); //add //expected.put("username", username); expected.put("code", code.toString()); expected.put("msg", msg.toString()); //expected.put("error_type", data.toString()); String jsonResult = g.toJson(expected); if (code.toString() == "00") { System.out.println("success"); } else { System.out.println("fail"); } return jsonResult; }
From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java
@Test public void resultHasData() throws Exception { File resultFile = aggregateSingle(); try (FileReader fr = new FileReader(resultFile)) { List<String> result = IOUtils.readLines(fr); assertThat(result, hasItems(containsString("0,DevOps,49.2,16.6167,Brno,Male,6"))); }//from www . ja va 2 s . c om }
From source file:com.github.mojos.distribute.PackageMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (version != null) { packageVersion = version;/* ww w .j a v a2s.c o m*/ } //Copy sourceDirectory final File sourceDirectoryFile = new File(sourceDirectory); final File buildDirectory = Paths.get(project.getBuild().getDirectory(), "py").toFile(); try { FileUtils.copyDirectory(sourceDirectoryFile, buildDirectory); } catch (IOException e) { throw new MojoExecutionException("Failed to copy source", e); } final File setup = Paths.get(buildDirectory.getPath(), "setup.py").toFile(); final boolean setupProvided = setup.exists(); final File setupTemplate = setupProvided ? setup : Paths.get(buildDirectory.getPath(), "setup-template.py").toFile(); try { if (!setupProvided) { //update VERSION to latest version List<String> lines = new ArrayList<String>(); final InputStream inputStream = new BufferedInputStream(new FileInputStream(setupTemplate)); try { lines.addAll(IOUtils.readLines(inputStream)); } finally { inputStream.close(); } int index = 0; for (String line : lines) { line = line.replace(VERSION, packageVersion); line = line.replace(PROJECT_NAME, packageName); lines.set(index, line); index++; } final OutputStream outputStream = new FileOutputStream(setup); try { IOUtils.writeLines(lines, "\n", outputStream); } finally { outputStream.flush(); outputStream.close(); } } //execute setup script ProcessBuilder processBuilder = new ProcessBuilder(pythonExecutable, setup.getCanonicalPath(), "bdist_egg"); processBuilder.directory(buildDirectory); processBuilder.redirectErrorStream(true); Process pr = processBuilder.start(); int exitCode = pr.waitFor(); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = ""; while ((line = buf.readLine()) != null) { getLog().info(line); } if (exitCode != 0) { throw new MojoExecutionException("python setup.py returned error code " + exitCode); } } catch (FileNotFoundException e) { throw new MojoExecutionException("Unable to find " + setup.getPath(), e); } catch (IOException e) { throw new MojoExecutionException("Unable to read " + setup.getPath(), e); } catch (InterruptedException e) { throw new MojoExecutionException("Unable to execute python " + setup.getPath(), e); } }