List of usage examples for java.io PrintStream printf
public PrintStream printf(String format, Object... args)
From source file:org.kuali.kfs.module.ld.document.web.struts.LaborCorrectionAction.java
/** * This handles the action for uploading a file * //from w w w. java2s . co m * @see org.kuali.kfs.gl.document.web.struts.CorrectionAction#uploadFile(org.apache.struts.action.ActionMapping, * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public ActionForward uploadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, IOException, Exception { LOG.debug("uploadFile() started"); LaborCorrectionForm laborCorrectionForm = (LaborCorrectionForm) form; LaborCorrectionDocument document = laborCorrectionForm.getLaborCorrectionDocument(); Date now = CorrectionAction.dateTimeService.getCurrentDate(); //creat file after all enries loaded well //OriginEntryGroup newOriginEntryGroup = CorrectionAction.originEntryGroupService.createGroup(today, OriginEntrySource.LABOR_CORRECTION_PROCESS_EDOC, false, false, false); FormFile sourceFile = laborCorrectionForm.getSourceFile(); String llcpDirectory = SpringContext.getBean(LaborCorrectionDocumentService.class).getLlcpDirectoryName(); String fullFileName = llcpDirectory + File.separator + sourceFile.getFileName() + "-" + CorrectionAction.dateTimeService.toDateTimeStringForFilename(now); BufferedReader br = new BufferedReader(new InputStreamReader(sourceFile.getInputStream())); //create a file File uploadedFile = new File(fullFileName); PrintStream uploadedFilePrintStream; try { uploadedFilePrintStream = new PrintStream(uploadedFile); } catch (IOException e) { throw new RuntimeException(e); } //write entries to file int loadedCount = 0; String stringLine; while ((stringLine = br.readLine()) != null) { try { uploadedFilePrintStream.printf("%s\n", stringLine); loadedCount++; } catch (Exception e) { throw new IOException(e.toString()); } } uploadedFilePrintStream.close(); int recordCountFunctionalityLimit = CorrectionDocumentUtils.getRecordCountFunctionalityLimit(); if (CorrectionDocumentUtils.isRestrictedFunctionalityMode(loadedCount, recordCountFunctionalityLimit)) { laborCorrectionForm.setRestrictedFunctionalityMode(true); laborCorrectionForm.setDataLoadedFlag(false); document.setCorrectionInputFileName(fullFileName); laborCorrectionForm.setInputFileName(fullFileName); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(laborCorrectionForm.getEditMethod())) { // the group size is not suitable for manual editing because it is too large if (recordCountFunctionalityLimit == CorrectionDocumentUtils.RECORD_COUNT_FUNCTIONALITY_LIMIT_IS_NONE) { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_ANY_GROUP); } else { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_LARGE_GROUP, String.valueOf(recordCountFunctionalityLimit)); } } } else { laborCorrectionForm.setRestrictedFunctionalityMode(false); if (loadedCount > 0) { //now we can load all data from file List<LaborOriginEntry> originEntryList = new ArrayList(); Map loadMessageMap = laborOriginEntryService .getEntriesByGroupIdWithPath(uploadedFile.getAbsolutePath(), originEntryList); //put errors on GlobalVariables if (loadMessageMap.size() > 0) { Iterator iter = loadMessageMap.keySet().iterator(); while (iter.hasNext()) { Integer lineNumber = (Integer) iter.next(); List<Message> messageList = (List<Message>) loadMessageMap.get(lineNumber); if (messageList.size() > 0) { for (Message errorMmessage : messageList) { GlobalVariables.getMessageMap().putError("fileUpload", KFSKeyConstants.ERROR_INVALID_FORMAT_ORIGIN_ENTRY_FROM_TEXT_FILE, new String[] { lineNumber.toString(), errorMmessage.toString() }); } } } return mapping.findForward(KFSConstants.MAPPING_BASIC); } // Set all the data that we know laborCorrectionForm.setDataLoadedFlag(true); laborCorrectionForm.setInputFileName(fullFileName); document.setCorrectionInputFileName(fullFileName); List<OriginEntryFull> originEntryFullList = new ArrayList(); originEntryFullList.addAll(originEntryList); loadAllEntries(originEntryFullList, laborCorrectionForm); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(laborCorrectionForm.getEditMethod())) { laborCorrectionForm.setEditableFlag(false); laborCorrectionForm.setManualEditFlag(true); } } else { GlobalVariables.getMessageMap().putError("fileUpload", KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_NO_RECORDS); } } if (document.getCorrectionChangeGroup().isEmpty()) { document.addCorrectionChangeGroup(new CorrectionChangeGroup()); } return mapping.findForward(KFSConstants.MAPPING_BASIC); }
From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborYearEndBalanceForwardServiceImpl.java
/** * post the qualified balance into origin entry table for the further labor ledger processing * /* www . j a v a 2 s . c o m*/ * @param balance the given ledger balance that will be carried forward * @param newFiscalYear the new fiscal year * @param validGroup the group that the posted transaction belongs to * @param postingDate the date the transaction is posted */ protected void postAsOriginEntry(LedgerBalanceForYearEndBalanceForward balance, LaborOriginEntry originEntry, PrintStream balanceForwardsPs, Date postingDate) { try { originEntry.setAccountNumber(balance.getAccountNumber()); originEntry.setChartOfAccountsCode(balance.getChartOfAccountsCode()); originEntry.setSubAccountNumber(balance.getSubAccountNumber()); originEntry.setFinancialObjectCode(balance.getFinancialObjectCode()); originEntry.setFinancialSubObjectCode(balance.getFinancialSubObjectCode()); originEntry.setFinancialBalanceTypeCode(balance.getFinancialBalanceTypeCode()); originEntry.setFinancialObjectTypeCode(balance.getFinancialObjectTypeCode()); originEntry.setPositionNumber(balance.getPositionNumber()); originEntry.setEmplid(balance.getEmplid()); originEntry.setDocumentNumber(balance.getFinancialBalanceTypeCode() + balance.getAccountNumber()); originEntry.setProjectCode(KFSConstants.getDashProjectCode()); originEntry.setUniversityFiscalPeriodCode(KFSConstants.PERIOD_CODE_CG_BEGINNING_BALANCE); KualiDecimal transactionAmount = balance.getAccountLineAnnualBalanceAmount(); transactionAmount = transactionAmount.add(balance.getContractsGrantsBeginningBalanceAmount()); originEntry.setTransactionLedgerEntryAmount(transactionAmount.abs()); originEntry.setTransactionDebitCreditCode(DebitCreditUtil.getDebitCreditCode(transactionAmount, false)); originEntry.setTransactionLedgerEntrySequenceNumber(null); originEntry.setTransactionTotalHours(BigDecimal.ZERO); originEntry.setTransactionDate(postingDate); try { balanceForwardsPs.printf("%s\n", originEntry.getLine()); } catch (Exception e) { throw new RuntimeException(e.toString()); } } catch (Exception e) { LOG.error(e); } }
From source file:org.kuali.kfs.module.ar.service.impl.ContractsGrantsInvoiceCreateDocumentServiceImpl.java
protected void writeToReport(String proposalNumber, String accountNumber, String awardBeginningDate, String awardEndingDate, String awardTotalAmount, String cumulativeExpenses, PrintStream printStream) throws IOException { printStream.printf("%15s", proposalNumber); printStream.printf("%18s", accountNumber); printStream.printf("%20s", awardBeginningDate); printStream.printf("%19s", awardEndingDate); printStream.printf("%15s", awardTotalAmount); printStream.printf("%23s", cumulativeExpenses); printStream.printf("\r\n"); }
From source file:gov.nasa.ensemble.dictionary.nddl.ParseInterpreter.java
/** * Function that writes out the model file specified by the given output * stream and based on a given Activity Dictionary that has already been * parsed/*from w w w . ja v a2 s.c om*/ * * @param shortName * of oStrm */ public void writeCompats(OutputStream oStrm, String objFileName) { PrintStream out = new PrintStream(oStrm); out.printf("#include \"PlannerConfig.nddl\"\n" + "#include \"Resources.nddl\"\n" + "#include \"%s\"\n\n\n" + "#include \"Boolean_Object.nddl\"\n", objFileName); this.writePassiveCompats(oStrm); if (ModelGenerator.getPreferences().useResourceSolvingForStateConstraints()) { this.writeActiveTimelineCompats(oStrm); this.writeActiveResourceCompats(oStrm); } else { this.writeActiveCompats(oStrm); } for (ADTranslator translator : adTranslators) translator.writeCompats(out); }
From source file:org.kuali.kfs.gl.document.web.struts.CorrectionAction.java
public ActionForward uploadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, IOException, Exception { LOG.debug("uploadFile() started"); CorrectionForm correctionForm = (CorrectionForm) form; GeneralLedgerCorrectionProcessDocument document = (GeneralLedgerCorrectionProcessDocument) correctionForm .getDocument();/*from w w w. j a va 2 s . c o m*/ Date now = CorrectionAction.dateTimeService.getCurrentDate(); //creat file after all enries loaded well //OriginEntryGroup newOriginEntryGroup = CorrectionAction.originEntryGroupService.createGroup(today, OriginEntrySource.GL_CORRECTION_PROCESS_EDOC, false, false, false); FormFile sourceFile = correctionForm.getSourceFile(); String glcpDirectory = SpringContext.getBean(CorrectionDocumentService.class).getGlcpDirectoryName(); String fullFileName = glcpDirectory + File.separator + sourceFile.getFileName() + "-" + CorrectionAction.dateTimeService.toDateTimeStringForFilename(now); BufferedReader br = new BufferedReader(new InputStreamReader(sourceFile.getInputStream())); //create a file File uploadedFile = new File(fullFileName); PrintStream uploadedFilePrintStream; try { uploadedFilePrintStream = new PrintStream(uploadedFile); } catch (IOException e) { throw new RuntimeException(e); } //write entries to file int loadedCount = 0; String stringLine; while ((stringLine = br.readLine()) != null) { try { uploadedFilePrintStream.printf("%s\n", stringLine); loadedCount++; } catch (Exception e) { throw new IOException(e.toString()); } } uploadedFilePrintStream.close(); int recordCountFunctionalityLimit = CorrectionDocumentUtils.getRecordCountFunctionalityLimit(); if (CorrectionDocumentUtils.isRestrictedFunctionalityMode(loadedCount, recordCountFunctionalityLimit)) { correctionForm.setRestrictedFunctionalityMode(true); correctionForm.setDataLoadedFlag(false); document.setCorrectionInputFileName(fullFileName); correctionForm.setInputFileName(fullFileName); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(correctionForm.getEditMethod())) { // the group size is not suitable for manual editing because it is too large if (recordCountFunctionalityLimit == CorrectionDocumentUtils.RECORD_COUNT_FUNCTIONALITY_LIMIT_IS_NONE) { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_ANY_GROUP); } else { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_LARGE_GROUP, String.valueOf(recordCountFunctionalityLimit)); } } } else { correctionForm.setRestrictedFunctionalityMode(false); if (loadedCount > 0) { //now we can load all data from file List<OriginEntryFull> originEntryList = new ArrayList(); Map loadMessageMap = originEntryService.getEntriesByGroupIdWithPath(uploadedFile.getAbsolutePath(), originEntryList); //put errors on GlobalVariables if (loadMessageMap.size() > 0) { Iterator iter = loadMessageMap.keySet().iterator(); while (iter.hasNext()) { Integer lineNumber = (Integer) iter.next(); List<Message> messageList = (List<Message>) loadMessageMap.get(lineNumber); if (messageList.size() > 0) { for (Message errorMmessage : messageList) { GlobalVariables.getMessageMap().putError("fileUpload", KFSKeyConstants.ERROR_INVALID_FORMAT_ORIGIN_ENTRY_FROM_TEXT_FILE, new String[] { lineNumber.toString(), errorMmessage.toString() }); } } } return mapping.findForward(KFSConstants.MAPPING_BASIC); } // Set all the data that we know correctionForm.setDataLoadedFlag(true); correctionForm.setInputFileName(fullFileName); document.setCorrectionInputFileName(fullFileName); loadAllEntries(originEntryList, correctionForm); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(correctionForm.getEditMethod())) { correctionForm.setEditableFlag(false); correctionForm.setManualEditFlag(true); } } else { GlobalVariables.getMessageMap().putError("fileUpload", KFSKeyConstants.ERROR_GL_ERROR_CORRECTION_NO_RECORDS); } } if (document.getCorrectionChangeGroup().isEmpty()) { document.addCorrectionChangeGroup(new CorrectionChangeGroup()); } return mapping.findForward(KFSConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.gl.document.web.struts.CorrectionAction.java
public ActionForward uploadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, IOException, Exception { LOG.debug("uploadFile() started"); CorrectionForm correctionForm = (CorrectionForm) form; GeneralLedgerCorrectionProcessDocument document = (GeneralLedgerCorrectionProcessDocument) correctionForm .getDocument();/* www . j ava 2 s.c o m*/ Date now = CorrectionAction.dateTimeService.getCurrentDate(); //creat file after all enries loaded well //OriginEntryGroup newOriginEntryGroup = CorrectionAction.originEntryGroupService.createGroup(today, OriginEntrySource.GL_CORRECTION_PROCESS_EDOC, false, false, false); FormFile sourceFile = correctionForm.getSourceFile(); String glcpDirectory = SpringContext.getBean(CorrectionDocumentService.class).getGlcpDirectoryName(); String fullFileName = glcpDirectory + File.separator + sourceFile.getFileName() + "-" + CorrectionAction.dateTimeService.toDateTimeStringForFilename(now); BufferedReader br = new BufferedReader(new InputStreamReader(sourceFile.getInputStream())); //create a file File uploadedFile = new File(fullFileName); PrintStream uploadedFilePrintStream; try { uploadedFilePrintStream = new PrintStream(uploadedFile); } catch (IOException e) { throw new RuntimeException(e); } //write entries to file int loadedCount = 0; String stringLine; while ((stringLine = br.readLine()) != null) { try { uploadedFilePrintStream.printf("%s\n", stringLine); loadedCount++; } catch (Exception e) { throw new IOException(e.toString()); } } uploadedFilePrintStream.close(); int recordCountFunctionalityLimit = CorrectionDocumentUtils.getRecordCountFunctionalityLimit(); if (CorrectionDocumentUtils.isRestrictedFunctionalityMode(loadedCount, recordCountFunctionalityLimit)) { correctionForm.setRestrictedFunctionalityMode(true); correctionForm.setDataLoadedFlag(false); document.setCorrectionInputFileName(fullFileName); correctionForm.setInputFileName(fullFileName); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(correctionForm.getEditMethod())) { // the group size is not suitable for manual editing because it is too large if (recordCountFunctionalityLimit == CorrectionDocumentUtils.RECORD_COUNT_FUNCTIONALITY_LIMIT_IS_NONE) { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, OLEKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_ANY_GROUP); } else { GlobalVariables.getMessageMap().putError(SYSTEM_AND_EDIT_METHOD_ERROR_KEY, OLEKeyConstants.ERROR_GL_ERROR_CORRECTION_UNABLE_TO_MANUAL_EDIT_LARGE_GROUP, String.valueOf(recordCountFunctionalityLimit)); } } } else { correctionForm.setRestrictedFunctionalityMode(false); if (loadedCount > 0) { //now we can load all data from file List<OriginEntryFull> originEntryList = new ArrayList(); Map loadMessageMap = originEntryService.getEntriesByGroupIdWithPath(uploadedFile.getAbsolutePath(), originEntryList); //put errors on GlobalVariables if (loadMessageMap.size() > 0) { Iterator iter = loadMessageMap.keySet().iterator(); while (iter.hasNext()) { Integer lineNumber = (Integer) iter.next(); List<Message> messageList = (List<Message>) loadMessageMap.get(lineNumber); if (messageList.size() > 0) { for (Message errorMmessage : messageList) { GlobalVariables.getMessageMap().putError("fileUpload", OLEKeyConstants.ERROR_INVALID_FORMAT_ORIGIN_ENTRY_FROM_TEXT_FILE, new String[] { lineNumber.toString(), errorMmessage.toString() }); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); } // Set all the data that we know correctionForm.setDataLoadedFlag(true); correctionForm.setInputFileName(fullFileName); document.setCorrectionInputFileName(fullFileName); loadAllEntries(originEntryList, correctionForm); if (CorrectionDocumentService.CORRECTION_TYPE_MANUAL.equals(correctionForm.getEditMethod())) { correctionForm.setEditableFlag(false); correctionForm.setManualEditFlag(true); } } else { GlobalVariables.getMessageMap().putError("fileUpload", OLEKeyConstants.ERROR_GL_ERROR_CORRECTION_NO_RECORDS); } } if (document.getCorrectionChangeGroup().isEmpty()) { document.addCorrectionChangeGroup(new CorrectionChangeGroup()); } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:gov.nasa.ensemble.dictionary.nddl.ParseInterpreter.java
/** * Function that writes out the initial state file specified by the given * output stream and based on a given Activity Dictionary that has already * been parsed//from ww w.j av a 2 s . co m * * @param shortName * of oStrm */ public void writeInitialState(OutputStream oStrm, String modelFileName) { PrintStream out = new PrintStream(oStrm); // output common header lines out.printf("#include \"%s\"\n\n" + "PlannerConfig plannerConfiguration = new PlannerConfig(-10, +100000000, 10000, 10000);\n\n" + "ContainerObj Containers = new ContainerObj();\n" + "\tContainerObj.close();\n" + "InitialConds Incons = new InitialConds();\n" + "\tInitialConds.close();\n" + "Misc MiscClass = new Misc();\n" + "\tMisc.close();\n\n", modelFileName); if (CPUwindow != null) { out.printf("CPU_Windows Windows = new CPU_Windows();\n", modelFileName); out.print("\tCPU_Windows.close();\n"); } // instantiate subsystems objects for (String subsys : subsystemActivitiesMap.keySet()) { out.printf("%s Sys_%s = new %s();\n", subsys, subsys, subsys); out.printf("\t%s.close();\n", subsys); } out.println(); // initialize state resources (Enum and Threshold) // this needs to be coordinated with how Incon Activity is defined // for now, make everything is set to 0.0 // hence, they all must be set in the incon or there will be violations for (String state : stateNames) { List<String> stateValues = stateValuesMap.get(state); if (stateValues != null) { for (String val : stateValues) { String stateVal = NDDLUtil.escape(state + "_" + val); out.printf("%s SC_%s = new %s(0.0);\n", stateVal, stateVal, stateVal); out.printf("\t%s.close();\n", stateVal); } } // handle the negated state values Set<String> stateNotValues = stateNotValuesMap.get(state); if (stateNotValues != null) { for (String val : stateNotValues) { String stateVal = NDDLUtil.escape("not_" + state + "_" + val); out.printf("%s SC_%s = new %s(0.0);\n", stateVal, stateVal, stateVal); out.printf("\t%s.close();\n", stateVal); } } } out.println(); // initialize claimable resources // MODIFICATION: everything is now initialized to zero // so that the icon must specify the resource's value, not a delta for (String claim : claimNames) { String claimName = NDDLUtil.escape(claim); out.printf("%s UCR_%s = new %s(0.0);\n", claimName, claimName, claimName); out.printf("\t%s.close();\n", claimName); } out.println(); // MODIFICATION: everything is now initialized to zero // so that the icon must specify the resource's value, not a delta for (ESharableResourceDef share : allShares) { String shareName = NDDLUtil.escape(share.getName()); out.printf("%s MCR_%s = new %s(0.0, %f);\n", shareName, shareName, shareName, share.getCapacity().floatValue()); out.printf("\t%s.close();\n", shareName); } out.println(); // instantiate claim enforcement timelines for (String claim : claimNames) { String claimName = NDDLUtil.escape(claim); out.printf("Active_%s TL_%s = new Active_%s();\n", claimName, claimName, claimName); out.printf("\tActive_%s.close();\n", claimName); } out.println(); // instantiate Enum state mutex enforcement timelines // PHM 12/07/2011 Empty for Resource Solving for (String mutex : exclusiveActsStatesMap.keySet()) { String mutexString = NDDLUtil.escape(mutex); out.printf("Active_%s TL_%s = new Active_%s();\n", mutexString, mutexString, mutexString); out.printf("\tActive_%s.close();\n", mutexString); } // for (String mutex : exclusiveActsStatesMap2.keySet()) { // out.printf("Active_%s TL_%s = new Active_%s();\n", mutex, mutex, // mutex); // } // instantiate Threshold enforcement timelines for (EStateResourceDef state : allStates) { String stateTypeName = NDDLUtil.escape(state.getName()); if (stateTypesMap.containsKey(stateTypeName) && stateTypesMap.get(stateTypeName).equals("Threshold")) { for (String val : stateValuesMap.get(stateTypeName)) { String stateName = NDDLUtil.escape(state.getName() + "_" + val); out.printf("Active_%s TL_%s = new Active_%s();\n", stateName, stateName, stateName); out.printf("\tActive_%s.close();\n", stateName); } } } for (ADTranslator translator : adTranslators) translator.writeInitialState(out); // The entire DB is no longer closed; instead, each class is closed except Active_Enforcer // out.print("close();\n"); }
From source file:org.kuali.kfs.gl.batch.service.impl.ScrubberProcessImpl.java
protected void createOutputEntry(OriginEntryInformation entry, PrintStream ps) throws IOException { try {/*from w ww. jav a 2 s. co m*/ ps.printf("%s\n", entry.getLine()); } catch (Exception e) { throw new IOException(e.toString()); } }
From source file:org.kuali.kfs.gl.batch.service.impl.ScrubberProcessImpl.java
protected void createOutputEntry(String line, PrintStream ps) throws IOException { try {//from w w w .ja va2s . co m ps.printf("%s\n", line); } catch (Exception e) { throw new IOException(e.toString()); } }