List of usage examples for org.apache.commons.io.input ReaderInputStream ReaderInputStream
public ReaderInputStream(Reader reader)
From source file:org.strasa.web.updatestudy.view.RawDataView.java
@NotifyChange("*") @Command("uploadCSV") public void uploadCSV(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx, @ContextParam(ContextType.VIEW) Component view) { UploadEvent event = (UploadEvent) ctx.getTriggerEvent(); // System.out.println(event.getMedia().getStringData()); String name = event.getMedia().getName(); if (tempFile == null) try {/*from w w w .j av a2 s . c o m*/ tempFile = File.createTempFile(name, ".tmp"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (!name.endsWith(".csv")) { Messagebox.show("Error: File must be a text-based csv format", "Upload Error", Messagebox.OK, Messagebox.ERROR); return; } InputStream in = event.getMedia().isBinary() ? event.getMedia().getStreamData() : new ReaderInputStream(event.getMedia().getReaderData()); FileUtilities.uploadFile(tempFile.getAbsolutePath(), in); BindUtils.postNotifyChange(null, null, this, "*"); ArrayList<String> invalidHeader = new ArrayList<String>(); boolean isHeaderValid = true; try { StudyVariableManagerImpl studyVarMan = new StudyVariableManagerImpl(); CSVReader reader = new CSVReader(new FileReader(tempFile.getAbsolutePath())); String[] header = reader.readNext(); for (String column : header) { if (!studyVarMan.hasVariable(column)) { invalidHeader.add(column); isHeaderValid = false; } } List<String[]> dataPrep = reader.readAll(); dataPrep.remove(0); if (!new StudyManagerImpl().validateCSVDataForGermplasmComparision(this.studyID, dataPrep, 0, this.isRaw)) { Map<String, Object> arguments = new HashMap<String, Object>(); arguments.put("list", new StudyManagerImpl().getUnknownGermplasmFromCSVData(this.studyID, dataPrep, 0, this.isRaw)); String template = "/user/updatestudy/validategermplasmbox.zul"; Window window = (Window) Executions.createComponents(template, null, arguments); window.doModal(); } ; System.out.println(invalidHeader.size()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } isVariableDataVisible = true; dataFileName = name; if (!isHeaderValid) openCSVHeaderValidator(tempFile.getAbsolutePath(), false); else { refreshCsv(); if (this.isUpdateMode) isNewDataSet = true; } }
From source file:org.strasa.web.uploadstudy.view.model.StudyGermplasmInfo.java
@NotifyChange({ "lstStudyGermplasm", "lstKnownGermplasm" }) @Command("uploadGenotypeData") public void uploadGenotypeData(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx, @ContextParam(ContextType.VIEW) Component view) { UploadEvent event = (UploadEvent) ctx.getTriggerEvent(); // System.out.println(event.getMedia().getStringData()); String name = event.getMedia().getName(); if (!name.endsWith(".csv")) { Messagebox.show("Error: File must be a text-based CSV format", "Upload Error", Messagebox.OK, Messagebox.ERROR);//from w w w .j a v a 2 s . c o m return; } try { String filename = name + Encryptions.encryptStringToNumber(name, new Date().getTime()); File tempGenoFile = File.createTempFile(filename, ".tmp"); InputStream in = event.getMedia().isBinary() ? event.getMedia().getStreamData() : new ReaderInputStream(event.getMedia().getReaderData()); FileUtilities.uploadFile(tempGenoFile.getAbsolutePath(), in); List<GermplasmExt> lstGermplasm = CSVToBean(tempGenoFile); for (GermplasmExt germData : lstGermplasm) { if (!StringUtils.isNullOrEmpty(germData.getGermplasmname())) { if (lstStudyGermplasm.containsKey(germData.getGermplasmname())) { lstStudyGermplasm.get(germData.getGermplasmname()) .setGermplasmtypeid(getGermplasmTypeById(germData.getGermplasmtype())); lstStudyGermplasm.get(germData.getGermplasmname()).setValueFromeGermplasmEx(germData, lstGermplasmType); lstStudyGermplasm.get(germData.getGermplasmname()).setGermplasmExCharacteristic(germData); } } } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:org.strasa.web.uploadstudy.view.model.UploadData.java
@NotifyChange("*") @Command("uploadCSV") public void uploadCSV(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx, @ContextParam(ContextType.VIEW) Component view) { UploadEvent event = (UploadEvent) ctx.getTriggerEvent(); // System.out.println(event.getMedia().getStringData()); String name = event.getMedia().getName(); if (tempFile == null) try {/*w w w .ja v a 2s .co m*/ tempFile = File.createTempFile(name, ".tmp"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (!name.endsWith(".csv")) { Messagebox.show("Error: File must be a text-based csv format", "Upload Error", Messagebox.OK, Messagebox.ERROR); return; } InputStream in = event.getMedia().isBinary() ? event.getMedia().getStreamData() : new ReaderInputStream(event.getMedia().getReaderData()); FileUtilities.uploadFile(tempFile.getAbsolutePath(), in); BindUtils.postNotifyChange(null, null, this, "*"); ArrayList<String> invalidHeader = new ArrayList<String>(); boolean isHeaderValid = true; try { StudyVariableManagerImpl studyVarMan = new StudyVariableManagerImpl(); CSVReader reader = new CSVReader(new FileReader(tempFile.getAbsolutePath())); String[] header = reader.readNext(); for (String column : header) { if (!studyVarMan.hasVariable(column)) { invalidHeader.add(column); isHeaderValid = false; } } System.out.println("invalidHeader size " + invalidHeader.size()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } isVariableDataVisible = true; dataFileName = name; if (!isHeaderValid) openCSVHeaderValidator(tempFile.getAbsolutePath(), false); else { refreshCsv(); if (this.isUpdateMode) isNewDataset = true; } }
From source file:org.unigram.docvalidator.DocumentValidatorTest.java
private DocumentValidator getDocumentValidator() throws DocumentValidatorException { ValidatorConfiguration validatorConfig = ValidationConfigurationLoader .loadConfiguration(new ReaderInputStream(new StringReader("<?xml version=\"1.0\"?>\n" + "<component name=\"Validator\">" + " <component name=\"SentenceIterator\">" + " <component name=\"SentenceLength\">\n" + " <property name=\"max_length\" value=\"5\"/>\n" + " </component>" + " </component>" + "</component>"))); Configuration configuration = new Configuration(validatorConfig); return new DocumentValidator.Builder().setConfiguration(configuration).build(); }
From source file:org.wso2.carbon.registry.app.RemoteRegistry.java
private void restore(String path, Reader reader, AbderaClient abderaClient) throws RegistryException { InputStream is = new ReaderInputStream(reader); ClientResponse resp = abderaClient.post( baseURI + APPConstants.ATOM//w w w .j a va2 s. c o m + encodeURL(path + RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_DUMP), is, getAuthorization()); if (resp.getType() == Response.ResponseType.SUCCESS) { if (log.isDebugEnabled()) { log.debug("resource dump restored at " + path); } } else { String msg = "Restoring to " + path + " failed."; log.error(msg); throw new RegistryException(msg); } }
From source file:org.zanata.adapter.glossary.GlossaryPoReader.java
@Override public Map<LocaleId, List<GlossaryEntry>> extractGlossary(Reader reader, String qualifiedName) throws IOException { ReaderInputStream ris = new ReaderInputStream(reader); try {/*from www . j ava2 s .com*/ InputSource potInputSource = new InputSource(ris); potInputSource.setEncoding("utf8"); return extractTemplate(potInputSource, qualifiedName); } finally { ris.close(); } }
From source file:pl.nask.hsn2.framework.commands.WorkflowUploadRequestCmd.java
@Override public Operation execute(CommandContext<WorkflowUploadRequest> context) throws CommandExecutionException { try {// ww w . j a v a 2 s .c o m String id = WorkflowManager.getInstance().uploadWorkflow(context.getSourceOperation().getName(), new ReaderInputStream(new StringReader(context.getSourceOperation().getContent())), context.getSourceOperation().isOverride()); return new WorkflowUploadReply(id); } catch (Exception e) { return new WorkflowError(e.toString()); } }
From source file:pl.nask.hsn2.framwework.workflow.repository.GitRepositoryTest.java
@Test public void saveNewWorkflow() throws WorkflowRepoException { LOGGER.info("saving workflow..."); StringReader reader = new StringReader(testInput); InputStream is = new ReaderInputStream(reader); repo.saveWorkflow(WORKFLOW_NAME, is); Assert.assertTrue(fileExists(WORKFLOW_NAME)); }
From source file:pl.nask.hsn2.framwework.workflow.repository.GitRepositoryTest.java
@Test(dependsOnMethods = "saveNewWorkflow") public void updateNewWorkflow() throws WorkflowRepoException, InterruptedException { LOGGER.info("updating workflow..."); StringReader reader = new StringReader(testInput2); InputStream is = new ReaderInputStream(reader); repo.saveWorkflow(WORKFLOW_NAME, is); Assert.assertTrue(fileExists(WORKFLOW_NAME)); }