Example usage for org.apache.commons.lang StringUtils leftPad

List of usage examples for org.apache.commons.lang StringUtils leftPad

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils leftPad.

Prototype

public static String leftPad(String str, int size) 

Source Link

Document

Left pad a String with spaces (' ').

Usage

From source file:script.manager.Printer.java

private void printScriptContents(final JSONArray recordNumbers) {
    TreeMap<Integer, String> candidate = CandidateIO.readCandidate();
    Iterator iterator = recordNumbers.iterator();
    while (iterator.hasNext()) {
        try {/* w  w w.  ja v  a  2 s. c  o  m*/
            final int candidateNo = Integer.parseInt((String) iterator.next());
            LOG.log(Level.INFO, "{0}| {1}", new Object[] {
                    StringUtils.leftPad(Integer.toString(candidateNo), 3), candidate.get(candidateNo) });
            final String contents = FileUtils.readFileToString(new File(candidate.get(candidateNo)),
                    StandardCharsets.UTF_8);
            LOG.log(Level.INFO, contents);
        } catch (NumberFormatException | IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
}

From source file:script.manager.Printer.java

private void printScriptNo() {
    TreeMap<Integer, String> candidate = CandidateIO.readCandidate();
    for (Map.Entry<Integer, String> entrySet : candidate.entrySet()) {
        final Integer no = entrySet.getKey();
        LOG.log(Level.INFO, "{0}| {1}",
                new Object[] { StringUtils.leftPad(Integer.toString(no), 3), entrySet.getValue() });
    }/*from w ww .  j av a 2  s  .  c o  m*/
}

From source file:script.manager.Printer.java

private void printDiffer() {
    List<String> dbScriptPathes = Registor.fetchFileList();
    Map<Integer, String> candidate = new LinkedHashMap<>();
    int index = 1;
    for (String dbScriptPath : dbScriptPathes) {
        final File expectedScriptlFile = new File(dbScriptPath);
        if (expectedScriptlFile.exists()) {
            try {
                final String contentsLive = FileUtils.readFileToString(expectedScriptlFile,
                        StandardCharsets.UTF_8);
                final String shaLive = DigestUtils.sha256Hex(contentsLive);
                final String contentsDb = Registor.fetchContents(dbScriptPath);
                final String shaDb = Registor.fetchSha(dbScriptPath);
                if (!shaDb.equals(shaLive)) {
                    LOG.log(Level.INFO, "{0}| {1}",
                            new Object[] { StringUtils.leftPad(Integer.toString(index), 3), dbScriptPath });
                    LOG.log(Level.INFO, StringUtils
                            .join(DiffUtil.getUnifiedDiff(contentsDb, contentsLive).iterator(), "\n"));
                    candidate.put(index, dbScriptPath);
                    index++;//from  ww w .  j  a v  a2  s  .com
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
    }
    CandidateIO.saveCandidates(candidate);
}

From source file:script.manager.Printer.java

private void printNotRan() {
    List<String> diff = DiffUtil.getUnifiedDiff(StringUtils.join(Registor.fetchFileList().iterator(), "\n"),
            StringUtils.join(generateLivePathList().iterator(), "\n"));
    List<String> numdiff = new ArrayList<>();
    List<String> removed = new ArrayList<>();
    Map<Integer, String> candidate = new LinkedHashMap<>();
    int index = 1;
    for (String diffline : diff) {
        if (diffline.startsWith("> ")) {
            final String path = StringUtils.substringAfter(diffline, "> ");//StringUtils.right(diffline, 3);
            numdiff.add("> " + StringUtils.leftPad(Integer.toString(index), 3) + "| " + path);
            candidate.put(index, path);/*ww  w . j a v  a  2s . co m*/
            index++;
        } else if (diffline.startsWith("< ")) {
            removed.add(diffline);
        }
    }
    numdiff.addAll(removed);
    CandidateIO.saveCandidates(candidate);
    LOG.log(Level.INFO, StringUtils.join(numdiff.iterator(), "\n"));
}

From source file:stroom.index.server.BenchmarkIndex.java

@Override
public void run() {
    init();/*from ww w . ja v  a2s.  c  o  m*/

    final long batchStartTime = System.currentTimeMillis();

    final IndexShardWriterImpl[] writers = new IndexShardWriterImpl[indexShards.length];
    for (int i = 0; i < writers.length; i++) {
        final IndexShard indexShard = indexShards[i];
        writers[i] = new IndexShardWriterImpl(indexShardService, indexFields, indexShard.getIndex(),
                indexShard);
        writers[i].setRamBufferSizeMB(ramBufferMbSize);
        writers[i].open(true);
    }
    final AtomicLong atomicLong = new AtomicLong();

    final long indexStartTime = System.currentTimeMillis();

    final ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(jobSize);
    for (int i = 0; i < jobSize; i++) {
        final Runnable r = () -> {
            long myId;
            while ((myId = atomicLong.incrementAndGet()) < docCount) {
                try {
                    final int idx = (int) (myId % writers.length);
                    writers[idx].addDocument(getDocument(myId));
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }
        };
        threadPoolExecutor.execute(r);
    }

    threadPoolExecutor.shutdown();

    // Wait for termination.
    while (!threadPoolExecutor.isTerminated()) {
        // Wait 1 second.
        ThreadUtil.sleep(1000);

        final long docsSoFar = atomicLong.get();
        final long secondsSoFar = (System.currentTimeMillis() - batchStartTime) / 1000;

        for (int i = 0; i < writers.length; i++) {
            final IndexShardWriterImpl impl = writers[i];
            final IndexShard indexShard = indexShards[i];

            if (secondsSoFar > 0) {
                final long docsPerSecond = docsSoFar / secondsSoFar;
                impl.sync();
                LOGGER.info("run() - " + StringUtils.rightPad(ModelStringUtil.formatCsv(docsSoFar), 10)
                        + " doc ps " + ModelStringUtil.formatCsv(docsPerSecond) + " ("
                        + indexShard.getFileSizeString() + ")");
            }
            if (nextCommit != null && docsSoFar > nextCommit) {
                impl.flush();
                nextCommit = ((docsSoFar / commitCount) * commitCount) + commitCount;
                LOGGER.info("run() - commit " + docsSoFar + " next commit is " + nextCommit);
            }
        }
    }
    final long indexEndTime = System.currentTimeMillis();
    final long secondsSoFar = (System.currentTimeMillis() - batchStartTime) / 1000;
    final long docsPerSecond = atomicLong.get() / secondsSoFar;

    for (final IndexShardWriter writer : writers) {
        writer.close();
    }

    final long batchEndTime = System.currentTimeMillis();

    LOGGER.info("runWrite() - Complete");
    LOGGER.info("=====================");
    LOGGER.info("");
    LOGGER.info("Using Args");
    LOGGER.info("==========");
    LoggerPrintStream traceStream = LoggerPrintStream.create(LOGGER, false);
    traceArguments(traceStream);
    traceStream.close();
    LOGGER.info("");
    LOGGER.info("Stats");
    LOGGER.info("=====");

    LOGGER.info("Open Time  " + toMsNiceString(indexStartTime - batchStartTime));
    LOGGER.info("Index Time " + toMsNiceString(indexEndTime - indexStartTime));
    LOGGER.info("Close Time " + toMsNiceString(batchEndTime - indexEndTime));
    LOGGER.info("Total Time " + toMsNiceString(batchEndTime - batchStartTime));
    LOGGER.info("");
    LOGGER.info("Final Docs PS " + ModelStringUtil.formatCsv(docsPerSecond));

    traceStream = LoggerPrintStream.create(LOGGER, false);
    for (int i = 0; i < writers.length; i++) {
        LOGGER.info("");
        final IndexShardWriterImpl impl = writers[i];
        LOGGER.info("Writer " + StringUtils.leftPad(String.valueOf(i), 2));
        LOGGER.info("=========");
        impl.trace(traceStream);
    }
    traceStream.close();

    LOGGER.info("");
    LOGGER.info("Search");
    LOGGER.info("=====");

    try {
        final IndexShardSearcherImpl[] reader = new IndexShardSearcherImpl[indexShards.length];
        final IndexReader[] readers = new IndexReader[indexShards.length];
        for (int i = 0; i < reader.length; i++) {
            reader[i] = new IndexShardSearcherImpl(indexShards[i]);
            reader[i].open();
            readers[i] = reader[i].getReader();
        }

        for (final String arg : docArgs) {
            doSearchOnField(readers, arg);
        }

        doSearchOnField(readers, "multifield");
        doSearchOnField(readers, "dupfield");

        LOGGER.info("=====");

        for (int i = 0; i < reader.length; i++) {
            reader[i].close();
        }

    } catch (final Exception ex) {
        ex.printStackTrace();
    }

}

From source file:stroom.index.server.BenchmarkIndex.java

public String toMsNiceString(final long value) {
    return StringUtils.leftPad(ModelStringUtil.formatCsv(value), 10) + " ms";
}

From source file:stroom.streamstore.server.fs.ManualCheckStreamPerformance.java

public static void averageTimeCheck(final String msg, final TimedAction provider) throws IOException {
    final HashMap<Thread, Long> threadTimes = new HashMap<>();
    for (int i = 0; i < testThreadCount; i++) {
        final Thread t = new Thread((() -> {
            try {
                threadTimes.put(Thread.currentThread(), provider.newTimedAction());
            } catch (final IOException e) {
                e.printStackTrace();/*from   ww  w .j  a  v  a2  s  . co m*/
            }
        }));

        threadTimes.put(t, 0L);
        t.start();
    }
    boolean running = false;
    do {
        ThreadUtil.sleep(1000);

        running = false;
        for (final Thread thread : threadTimes.keySet()) {
            if (thread.isAlive()) {
                running = true;
                break;
            }
        }
    } while (running);

    long totalTime = 0;
    for (final Thread thread : threadTimes.keySet()) {
        totalTime += threadTimes.get(thread);
    }
    final long average = totalTime / threadTimes.size();

    System.out.println(
            "Average for " + StringUtils.leftPad(msg, 20) + " is " + StringUtils.leftPad("" + average, 10));
}

From source file:stroom.util.StreamRestoreTool.java

public void processStreamTypeFeed(final String fileName, final String processStreamType,
        final String processFeedId, final char action) throws IOException, SQLException {
    final LineReader lineReader = new LineReader(new FileInputStream(fileName),
            StreamUtil.DEFAULT_CHARSET_NAME);

    String line = null;//from  w ww.  j  a v a 2s . c  om
    int lineCount = 0;
    int count = 0;

    long nextLog = System.currentTimeMillis() + 10000;

    while ((line = lineReader.nextLine()) != null) {
        final Map<String, String> streamAttributes = readAttributes(line, processStreamType, processFeedId);

        lineCount++;
        if (System.currentTimeMillis() > nextLog) {
            writeLine("Reading line " + lineCount + " " + line);
            nextLog = System.currentTimeMillis() + 10000;
        }

        if (processStreamType.equals(streamAttributes.get(STREAM_TYPE_PATH))
                && (processFeedId == null || processFeedId.equals(streamAttributes.get(FEED_ID)))) {
            final File systemFile = new File(line);
            if (action == 'd') {
                if (mock) {
                    writeLine("rm " + line);
                } else {
                    writeLine("rm " + line);
                    systemFile.delete();
                }
            }

            // Restore and a root file
            if (action == 'r' && "0".equals(streamAttributes.get(DEPTH))) {
                streamAttributes.putAll(readManifestAttributes(line));

                final Stream stream = new Stream();
                stream.setId(Long.parseLong(streamAttributes.get(StreamAttributeConstants.STREAM_ID)));
                stream.setVersion((byte) 1);

                stream.setCreateMs(DateUtil
                        .parseNormalDateTimeString(streamAttributes.get(StreamAttributeConstants.CREATE_TIME)));
                if (streamAttributes.containsKey(StreamAttributeConstants.EFFECTIVE_TIME)) {
                    stream.setEffectiveMs(DateUtil.parseNormalDateTimeString(
                            streamAttributes.get(StreamAttributeConstants.EFFECTIVE_TIME)));
                }
                if (stream.getEffectiveMs() == null) {
                    stream.setEffectiveMs(stream.getCreateMs());
                }

                if (streamAttributes.containsKey(StreamAttributeConstants.PARENT_STREAM_ID)) {
                    stream.setParentStreamId(
                            Long.valueOf(streamAttributes.get(StreamAttributeConstants.PARENT_STREAM_ID)));
                }
                stream.updateStatus(StreamStatus.UNLOCKED);
                stream.setFeed(Feed.createStub(Long.valueOf(streamAttributes.get(FEED_ID))));
                stream.setStreamType(StreamType
                        .createStub(getPathStreamTypeMap().get(streamAttributes.get(STREAM_TYPE_PATH))));

                final String logInfo = StringUtils.leftPad(String.valueOf(stream.getId()), 10) + " "
                        + DateUtil.createNormalDateTimeString(stream.getCreateMs());

                writeLine("Restore " + logInfo + " for file " + line);

                if (!mock) {
                    try {
                        try (PreparedStatement statement1 = getConnection().prepareStatement(
                                "insert into strm (id,ver, crt_ms,effect_ms, parnt_strm_id,stat, fk_fd_id,fk_strm_proc_id, fk_strm_tp_id) "
                                        + " values (?,1, ?,?, ?,?, ?,?, ?)")) {
                            int s1i = 1;
                            statement1.setLong(s1i++, stream.getId());

                            statement1.setLong(s1i++, stream.getCreateMs());
                            if (stream.getEffectiveMs() != null) {
                                statement1.setLong(s1i++, stream.getEffectiveMs());
                            } else {
                                statement1.setNull(s1i++, Types.BIGINT);
                            }

                            if (stream.getParentStreamId() != null) {
                                statement1.setLong(s1i++, stream.getParentStreamId());
                            } else {
                                statement1.setNull(s1i++, Types.BIGINT);
                            }
                            statement1.setByte(s1i++, stream.getStatus().getPrimitiveValue());

                            statement1.setLong(s1i++, stream.getFeed().getId());
                            statement1.setNull(s1i++, Types.BIGINT);

                            statement1.setLong(s1i++, stream.getStreamType().getId());

                            statement1.executeUpdate();
                            statement1.close();
                        }

                        try (PreparedStatement statement2 = getConnection().prepareStatement(
                                "insert into strm_vol (ver, fk_strm_id,fk_vol_id) " + " values (1, ?,?)")) {
                            int s2i = 1;
                            statement2.setLong(s2i++, stream.getId());
                            statement2.setLong(s2i++,
                                    getPathVolumeMap().get(streamAttributes.get(VOLUME_PATH)));
                            statement2.executeUpdate();
                            statement2.close();
                        }
                    } catch (final Exception ex) {
                        writeLine("Failed " + logInfo + " " + ex.getMessage());
                    }
                }
                count++;
            }
        }
    }
    writeLine("Processed " + ModelStringUtil.formatCsv(count) + " count");

}

From source file:stroom.util.StreamRestoreTool.java

public ArrayList<KeyCount> writeTable(final Collection<KeyCount> values, final String heading) {
    writeLine("========================");
    writeLine(heading);/*from w w  w.j av a 2 s.c o m*/
    writeLine("========================");
    final ArrayList<KeyCount> list = new ArrayList<>();
    list.addAll(values);
    sort(list);

    for (final KeyCount keyCount : list) {
        writeLine(StringUtils.rightPad(keyCount.getKey().toString(), KEY_PAD)
                + StringUtils.leftPad(ModelStringUtil.formatCsv(keyCount.getCount()), COUNT_PAD));
    }
    writeLine("========================");
    return list;

}

From source file:xc.mst.bo.record.RecordCounts.java

public String toString(String repoName) {
    StringBuilder sb = new StringBuilder();

    // This is for the purpose of making the totals appear last
    List<String> keys = new ArrayList<String>();
    for (String type : counts.keySet()) {
        if (!type.equals(TOTALS) && !type.equals(OTHER)) {
            keys.add(type);//from w ww  . j  a v a2 s. c  o m
        }
    }
    keys.add(OTHER);
    keys.add(TOTALS);
    for (String type : keys) {
        Map<String, AtomicInteger> counts4Type = counts.get(type);
        if (counts4Type == null)
            continue;

        type = StringUtils.rightPad(type, 25);
        int col = 0;
        List<String> colNames = new ArrayList<String>();
        colNames.addAll(INCOMING_STATUS_COLUMN_NAMES);
        if (RecordCounts.OUTGOING.equals(this.incomingOutgoing)) {
            colNames.addAll(UPD_PREV_COLUMN_NAMES.values());
        } else {
            colNames.add(UNEXPECTED_ERROR);
        }
        String date = "all time            ";
        LOG.debug("TOTALS_DATE.getTime(): " + TOTALS_DATE.getTime());
        LOG.debug("this.harvestStartDate.getTime(): " + this.harvestStartDate.getTime());
        if (this.harvestStartDate.getTime() != TOTALS_DATE.getTime()) {
            LOG.debug("new Util().printDateTime(this.harvestStartDate): "
                    + new Util().printDateTime(this.harvestStartDate));
            LOG.debug("new Util().printDateTime(TOTALS_DATE): " + new Util().printDateTime(TOTALS_DATE));

            date = new Util().printDateTime(this.harvestStartDate);
        }
        for (String updateType : colNames) {
            if (col == 0)
                sb.append("\n" + incomingOutgoing + " " + date + " " + type + " ");
            long num = 0;
            if (counts4Type.get(updateType) != null) {
                num = counts4Type.get(updateType).get();
            }
            DecimalFormat myFormatter = new DecimalFormat("###,###,###");
            String line = StringUtils.leftPad(updateType, 25) + ": "
                    + StringUtils.leftPad(myFormatter.format(num), 12) + "  ";
            sb.append(line);

            if (++col == 3) {
                col = 0;
            }
        }
    }

    return sb.toString();
}