Example usage for java.io PrintStream printf

List of usage examples for java.io PrintStream printf

Introduction

In this page you can find the example usage for java.io PrintStream printf.

Prototype

public PrintStream printf(String format, Object... args) 

Source Link

Document

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

Usage

From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborScrubberProcess.java

protected void createOutputEntry(String line, PrintStream ps) throws IOException {
    try {/*from  ww  w  .  java  2 s .c  om*/
        ps.printf("%s\n", line);
    } catch (Exception e) {
        throw new IOException(e.toString(), e);
    }
}

From source file:ed.db.mql.MQLShell.java

/**
 *   pretty print for a cursor.  also stolen from ed.js.Shell w/ some tweaks.
 * @param out stream to print to//from w  w  w.j av  a2s .  co  m
 * @param c cursor to print
 * @return size of set returned
 */
int displayCursor(PrintStream out, DBCursor c) {

    List<JSObject> all = new ArrayList<JSObject>();
    Map<String, Integer> fields = new TreeMap<String, Integer>();

    for (int i = 0; i < 30 && c.hasNext(); i++) {
        JSObject obj = c.next();
        all.add(obj);

        for (String f : obj.keySet(false)) {

            if (JSON.IGNORE_NAMES.contains(f))
                continue;

            Object blah = obj.get(f);

            Integer old = fields.get(f);
            if (old == null)
                old = 4;

            fields.put(f, Math.max(_string(f).length(), Math.max(old, _string(blah).length())));
        }
    }

    if (all.size() == 0) {
        return 0;
    }

    for (String f : fields.keySet()) {
        out.printf("%" + fields.get(f) + "s | ", f);
    }

    out.printf("\n");

    for (JSObject obj : all) {
        for (String f : fields.keySet()) {
            out.printf("%" + fields.get(f) + "s | ", _string(obj.get(f)));
        }
        out.printf("\n");
    }

    return all.size();
}

From source file:org.kuali.kfs.module.endow.batch.service.impl.GeneralLedgerInterfaceBatchProcessServiceImpl.java

protected void createOutputEntry(Transaction entry, PrintStream group) throws IOException {
    OriginEntryFull oef = new OriginEntryFull();

    oef.copyFieldsFromTransaction(entry);
    oef.setUniversityFiscalYear(null);//from www.  jav a  2s. co  m

    try {
        group.printf("%s\n", oef.getLine());
    } catch (Exception ex) {
        throw new IOException(ex.toString());
    }
}

From source file:org.apache.hadoop.zebra.io.BasicTable.java

static public void dumpInfo(String file, PrintStream out, Configuration conf, int indent) throws IOException {
    IOutils.indent(out, indent);/* ww w . j a va 2  s .c om*/
    out.println("Basic Table : " + file);
    Path path = new Path(file);
    try {
        BasicTable.Reader reader = new BasicTable.Reader(path, conf);
        String schemaStr = reader.getBTSchemaString();
        String storageStr = reader.getStorageString();
        IOutils.indent(out, indent);
        out.printf("Schema : %s\n", schemaStr);
        IOutils.indent(out, indent);
        out.printf("Storage Information : %s\n", storageStr);
        SortInfo sortInfo = reader.getSortInfo();
        if (sortInfo != null && sortInfo.size() > 0) {
            IOutils.indent(out, indent);
            String[] sortedCols = sortInfo.getSortColumnNames();
            out.println("Sorted Columns :");
            for (int nx = 0; nx < sortedCols.length; nx++) {
                if (nx > 0)
                    out.printf(" , ");
                out.printf("%s", sortedCols[nx]);
            }
            out.printf("\n");
        }
        IOutils.indent(out, indent);
        out.println("Column Groups within the Basic Table :");
        for (int nx = 0; nx < reader.colGroups.length; nx++) {
            IOutils.indent(out, indent);
            out.printf("\nColumn Group [%d] :", nx);
            if (reader.colGroups[nx] != null) {
                ColumnGroup.dumpInfo(reader.colGroups[nx].path, out, conf, indent);
            } else {
                // print basic info for deleted column groups.
                out.printf("\nColum Group : DELETED");
                out.printf("\nName : %s", reader.schemaFile.getName(nx));
                out.printf("\nSchema : %s\n", reader.schemaFile.cgschemas[nx].getSchema().toString());
            }
        }
    } catch (Exception e) {
        throw new IOException("BasicTable.Reader failed : " + e.getMessage());
    } finally {
        // no-op
    }
}

From source file:org.kuali.kfs.gl.batch.service.impl.PosterServiceImpl.java

protected void writeErrorEntry(String line, PrintStream invaliGroup) throws IOException {
    try {/*from   w ww .ja  v a  2s .c o  m*/
        invaliGroup.printf("%s\n", line);
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
}

From source file:org.wso2.msf4j.HttpServerTest.java

@Test(timeOut = 5000)
public void testConnectionClose() throws Exception {
    URL url = baseURI.resolve("/test/v1/connectionClose").toURL();

    // Fire http request using raw socket so that we can verify the connection get closed by the server
    // after the response.
    Socket socket = createRawSocket(url);
    try {/*w ww  . j a  v a  2s .c om*/
        PrintStream printer = new PrintStream(socket.getOutputStream(), false, "UTF-8");
        printer.printf("GET %s HTTP/1.1\r\n", url.getPath());
        printer.printf("Host: %s:%d\r\n", url.getHost(), url.getPort());
        printer.print("\r\n");
        printer.flush();

        // Just read everything from the response. Since the server will close the connection, the read loop should
        // end with an EOF. Otherwise there will be timeout of this test case
        String response = IOUtils.toString(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
        assertTrue(response.startsWith("HTTP/1.1 200 OK"));
    } finally {
        socket.close();
    }
}

From source file:org.kuali.kfs.gl.batch.service.impl.PosterServiceImpl.java

protected void createOutputEntry(Transaction entry, PrintStream group) throws IOException {
    OriginEntryFull oef = new OriginEntryFull();
    oef.copyFieldsFromTransaction(entry);
    try {/* ww  w  .  j  a  va  2 s .c o m*/
        group.printf("%s\n", oef.getLine());
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
}

From source file:org.kuali.ole.gl.batch.service.impl.NightlyOutServiceImpl.java

/**
 * Copies the approved pending ledger entries to origin entry table and generates a report
 * @see org.kuali.ole.gl.service.NightlyOutService#copyApprovedPendingLedgerEntries()
 *///  w  ww  . ja v  a2  s  . c  o  m
public void copyApprovedPendingLedgerEntries() {
    if (LOG.isInfoEnabled()) {
        LOG.info("copyApprovedPendingLedgerEntries() started");
    }
    Date today = new Date(dateTimeService.getCurrentTimestamp().getTime());

    Iterator pendingEntries = generalLedgerPendingEntryService.findApprovedPendingLedgerEntries();
    String outputFile = batchFileDirectoryName + File.separator
            + GeneralLedgerConstants.BatchFileSystem.NIGHTLY_OUT_FILE
            + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
    PrintStream outputFilePs = null;

    try {
        outputFilePs = new PrintStream(outputFile);
    } catch (IOException ioe) {
        throw new RuntimeException("Cannot open output file " + outputFile + " for writing", ioe);
    }

    EntryListReport entryListReport = new EntryListReport();
    LedgerSummaryReport nightlyOutLedgerSummaryReport = new LedgerSummaryReport();

    Collection<OriginEntryFull> group = new ArrayList<OriginEntryFull>();
    while (pendingEntries.hasNext()) {
        // get one pending entry
        GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntries.next();

        OriginEntryFull entry = new OriginEntryFull(pendingEntry);

        // write entry to reports
        entryListReport.writeEntry(entry, pendingEntryListReportWriterService);
        nightlyOutLedgerSummaryReport.summarizeEntry(entry);

        group.add(entry);

        // copy the pending entry to text file
        outputFilePs.printf("%s\n", entry.getLine());

        // update the pending entry to indicate it has been copied
        pendingEntry
                .setFinancialDocumentApprovedCode(OLEConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
        pendingEntry.setTransactionDate(today);

        generalLedgerPendingEntryService.save(pendingEntry);
    }

    outputFilePs.close();

    //create done file    
    String doneFileName = outputFile.replace(GeneralLedgerConstants.BatchFileSystem.EXTENSION,
            GeneralLedgerConstants.BatchFileSystem.DONE_FILE_EXTENSION);
    File doneFile = new File(doneFileName);
    if (!doneFile.exists()) {
        try {
            doneFile.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }

    // finish writing reports
    entryListReport.writeReportFooter(pendingEntryListReportWriterService);
    nightlyOutLedgerSummaryReport.writeReport(pendingEntrySummaryReportWriterService);
}

From source file:org.kuali.kfs.gl.batch.service.impl.NightlyOutServiceImpl.java

/**
 * Copies the approved pending ledger entries to origin entry table and generates a report
 * @see org.kuali.kfs.gl.service.NightlyOutService#copyApprovedPendingLedgerEntries()
 *//*from ww  w  . j  a  v a2  s .  c om*/
public void copyApprovedPendingLedgerEntries() {
    if (LOG.isInfoEnabled()) {
        LOG.info("copyApprovedPendingLedgerEntries() started");
    }
    Date today = new Date(dateTimeService.getCurrentTimestamp().getTime());

    Iterator pendingEntries = generalLedgerPendingEntryService.findApprovedPendingLedgerEntries();
    String outputFile = batchFileDirectoryName + File.separator
            + GeneralLedgerConstants.BatchFileSystem.NIGHTLY_OUT_FILE
            + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
    PrintStream outputFilePs = null;

    try {
        outputFilePs = new PrintStream(outputFile);
    } catch (IOException ioe) {
        throw new RuntimeException("Cannot open output file " + outputFile + " for writing", ioe);
    }

    EntryListReport entryListReport = new EntryListReport();
    LedgerSummaryReport nightlyOutLedgerSummaryReport = new LedgerSummaryReport();

    Collection<OriginEntryFull> group = new ArrayList<OriginEntryFull>();
    while (pendingEntries.hasNext()) {
        // get one pending entry
        GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntries.next();

        OriginEntryFull entry = new OriginEntryFull(pendingEntry);

        // write entry to reports
        entryListReport.writeEntry(entry, pendingEntryListReportWriterService);
        nightlyOutLedgerSummaryReport.summarizeEntry(entry);

        group.add(entry);

        // copy the pending entry to text file
        outputFilePs.printf("%s\n", entry.getLine());

        // update the pending entry to indicate it has been copied
        pendingEntry
                .setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.PROCESSED);
        pendingEntry.setTransactionDate(today);

        generalLedgerPendingEntryService.save(pendingEntry);
    }

    outputFilePs.close();

    //create done file    
    String doneFileName = outputFile.replace(GeneralLedgerConstants.BatchFileSystem.EXTENSION,
            GeneralLedgerConstants.BatchFileSystem.DONE_FILE_EXTENSION);
    File doneFile = new File(doneFileName);
    if (!doneFile.exists()) {
        try {
            doneFile.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }

    // finish writing reports
    entryListReport.writeReportFooter(pendingEntryListReportWriterService);
    nightlyOutLedgerSummaryReport.writeReport(pendingEntrySummaryReportWriterService);
}

From source file:org.kuali.kfs.gl.batch.CollectorBatch.java

/**
 * Sets defaults for fields not populated from file. Store an origin entry group, all gl entries and id billing entries from the
 * processed file. Also write the header for the duplicate file check.
 * /*  w w  w  . j  a  v  a2  s  . co m*/
 * @param originEntryGroup the group into which to store the origin entries
 * @param collectorReportData report data
 */
public void setDefaultsAndStore(CollectorReportData collectorReportData, String demergerOutputFileName,
        PrintStream originEntryOutputPs) {
    BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
    CollectorDetailService collectorDetailService = SpringContext.getBean(CollectorDetailService.class);

    // persistHeader is used to persist a collector header record into the DB
    CollectorHeader persistHeader = createCollectorHeaderForStorage();
    CollectorHeader foundHeader = retrieveDuplicateHeader();

    if (foundHeader != null) {
        // update the version number to prevent OptimisticLockingExceptions
        persistHeader.setVersionNumber(foundHeader.getVersionNumber());
    }
    businessObjectService.save(persistHeader);

    // store origin entries by using the demerger output file

    BufferedReader inputFileReader = null;
    try {
        inputFileReader = new BufferedReader(new FileReader(demergerOutputFileName));
        String line = null;
        while ((line = inputFileReader.readLine()) != null) {
            originEntryOutputPs.printf("%s\n", line);
        }
    } catch (IOException e) {
        throw new RuntimeException("IO Error encountered trying to persist collector batch.", e);
    } finally {
        IOUtils.closeQuietly(inputFileReader);
        inputFileReader = null;
    }
    Date nowDate = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
    RunDateService runDateService = SpringContext.getBean(RunDateService.class);
    Date createDate = new java.sql.Date((runDateService.calculateRunDate(nowDate).getTime()));

    Integer sequenceNumber = new Integer(0);
    Integer nextSequence = collectorDetailService.getNextCreateSequence(createDate);
    if (nextSequence != null) {
        sequenceNumber = nextSequence;
    }
    int countOfdetails = collectorDetails.size();
    for (int numSavedDetails = 0; numSavedDetails < countOfdetails; numSavedDetails++) {
        CollectorDetail idDetail = this.collectorDetails.get(numSavedDetails);
        //  setDefaultsCollectorDetail(idDetail);

        idDetail.setTransactionLedgerEntrySequenceNumber(++sequenceNumber);
        idDetail.setCreateDate(createDate);
        CollectorDetail foundIdDetail = (CollectorDetail) businessObjectService.retrieve(idDetail);
        if (foundIdDetail != null) {
            idDetail.setVersionNumber(foundIdDetail.getVersionNumber());
        }

        businessObjectService.save(idDetail);
    }

    collectorReportData.setNumSavedDetails(this, countOfdetails);
}