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

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

Introduction

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

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:nl.toolforge.karma.console.KarmaConsole.java

/**
 *
 * @param args  The working context (0), whether to update (1) and the command
 *              plus his options (3 ...).
 *//*from   w ww .j a  va 2 s. co  m*/
public void runConsole(String[] args) {

    Runtime.getRuntime().addShutdownHook(new Thread() {

        public void run() {

            if (immediate) {

                String text = FRONTEND_MESSAGES.getString("message.THANK_YOU");
                int length = text.length();

                writeln("\n");

                writeln(FRONTEND_MESSAGES.getString("message.EXIT"));

                StringBuffer g = new StringBuffer();
                g.append("\n\n").append(StringUtils.repeat("*", length));
                g.append("\n").append(text).append("\n");
                g.append(StringUtils.repeat("*", length)).append("\n");

                writeln(g.toString());
            }
        }
    });

    // If the '-w <working-context> option is used, use it.
    //
    WorkingContext workingContext;
    if (args[0] == null || args[0].equals("")) {
        workingContext = new WorkingContext(
                Preferences.userRoot().get(WorkingContext.WORKING_CONTEXT_PREFERENCE, WorkingContext.DEFAULT));
    } else {
        workingContext = new WorkingContext(args[0]);
    }

    writeln("\n" + "      _________________________________\n" + "      Welcome to Karma (R1.0 RC1) !!!!!\n"
            + "\n" + "      K     A     R        M        A\n" + "      .     .     .        .        .\n"
            + "      Karma Ain't Remotely Maven or Ant\n" + "      _________________________________\n");

    String karmaHome = System.getProperty("karma.home");
    if (karmaHome == null) {
        writeln("[ console ] Property 'karma.home' not set; logging will be written to "
                + System.getProperty("user.home") + File.separator + "logs.");
    } else {
        writeln("[ console ] Logging will be written to " + System.getProperty("karma.home") + File.separator
                + "logs.");
    }

    writeln("[ console ] Checking working context configuration for `" + workingContext.getName() + "`.");

    WorkingContextConfiguration configuration = null;

    try {
        configuration = new WorkingContextConfiguration(workingContext);
        try {
            configuration.load();
        } catch (WorkingContextException e) {
        }

        workingContext.configure(configuration);

        // Check the validity state of the configuration.
        //

        ErrorCode error = configuration.check();
        ErrorCode error2 = null;
        ErrorCode error3 = null;

        if (error != null) {
            writeln("[ console ] ** Error in working context configuration : " + error.getErrorMessage());
        }
        if (configuration.getManifestStore() == null) {
            writeln("[ console ] ** Error in working context configuration : Missing configuration for manifest store.");
        } else {
            error2 = configuration.getManifestStore().checkConfiguration();
            if (error2 != null) {
                writeln("[ console ] ** Error in working context configuration : " + error2.getErrorMessage());
            }
        }
        if (configuration.getLocationStore() == null) {
            writeln("[ console ] ** Error in working context configuration : Missing configuration for location store.");
        } else {
            error3 = configuration.getLocationStore().checkConfiguration();
            if (error3 != null) {
                writeln("[ console ] ** Error in working context configuration : " + error3.getErrorMessage());
            }
        }

        while (error != null || configuration.getManifestStore() == null || error2 != null
                || configuration.getLocationStore() == null || error3 != null) {

            // todo hier eerst de foutmelding tonen.

            // todo offline-mode ?

            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

            String start = "";
            try {
                while (!start.matches("n|y")) {
                    write("[ console ] Working context not initialized properly, start configurator ? [Y|N] (Y) :");
                    start = (reader.readLine().trim()).toLowerCase();
                    start = ("".equals(start) ? "y" : start);
                }
            } catch (IOException e) {
                start = "n";
            }

            if ("n".equals(start)) {
                writeln("[ console ] ** Configuration incomplete. Cannot start Karma.");
                writeln("[ console ] Check configuration manually.");

                System.exit(1);

            } else {
                Configurator configurator = new Configurator(workingContext, configuration);
                configurator.checkConfiguration();

                // Run checks once more.
                //
                error = configuration.check();
                if (configuration.getManifestStore() != null) {
                    error2 = configuration.getManifestStore().checkConfiguration();
                }
                if (configuration.getLocationStore() != null) {
                    error3 = configuration.getLocationStore().checkConfiguration();
                }
            }
        }

    } catch (RuntimeException r) {
        writeln("\n");
        if (logger.isDebugEnabled()) {
            r.printStackTrace();
        }
        System.exit(1);
    }

    writeln("[ console ] Configuration complete. Loading working context `" + workingContext.getName()
            + "` ...");

    // Right now, we have a valid configuration and continue to load the working context.
    //
    workingContext.configure(configuration);

    writeln("[ console ] Configuration can be manually updated in `"
            + workingContext.getWorkingContextConfigurationBaseDir() + "`");

    writeln("\n[ console ] Starting up console ...\n");

    //
    //
    commandContext = new CommandContext(workingContext);
    try {
        //      long start = System.currentTimeMillis();
        commandContext.init(new ConsoleCommandResponseHandler(this), new Boolean(args[1]).booleanValue());
        //      System.out.println("TOTAL STARTUP-TIME: " + (System.currentTimeMillis() - start));
    } catch (CommandException e) {
        logger.warn(e.getMessage());
    }

    try {

        // Open a reader, which is the actual command line ...
        //
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line = null;
        while (true) {

            prompt();

            if (reader != null || reader.readLine() != null) {
                line = reader.readLine().trim();
            }

            if ((line == null) || ("".equals(line.trim()))) {
                prompt();
                continue;
            }

            if ("[A".equals(line)) {
                line = lastLine;
                writeln(line);
            } else {
                lastLine = line;
            }

            try {
                commandContext.execute(line);
            } catch (CommandException e) {
                // The command context has already sent all required messages.
                //
            }
        }
    } catch (Throwable e) {
        writeln("\n");
        logger.fatal("Exception caught by KarmaConsole catch-all. ", e);

        String logfile = System.getProperty("karma.home", System.getProperty("user.home")) + File.separator
                + "logs" + File.separator + "karma-default.log";

        System.out.println("Something went BOOM inside of Karma.");
        System.out.println("Details: " + (e.getMessage() != null ? e.getMessage() : e.getClass().getName()));
        System.out.println("See the log file (" + logfile + ") for more information.");
        System.out.println(
                "Please report recurring problems to the Karma developers (http://sourceforge.net/tracker/?group_id=98766).");
        System.out.println("We apologize for the inconvenience.");
        System.out.println();

        System.exit(1);
    }
}

From source file:no.computas.zebra.exercises.Exercise.java

protected static String printIndividual(Individual individual) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Individual: " + individual.getLocalName() + "\n");
    StmtIterator properties = individual.listProperties();
    while (properties.hasNext()) {
        Statement s = properties.next();
        stringBuilder.append("  " + s.getPredicate().getLocalName() + " : " + s.getObject().toString() + "\n");
    }/* w  w  w .j  a  v  a2s. c o m*/
    properties.close();
    stringBuilder.append("\n");
    stringBuilder.append(StringUtils.repeat("-", 70));
    return stringBuilder.toString();
}

From source file:org.ambraproject.util.CategoryUtilsTest.java

private void printMap(CategoryView view, int depth) {
    String spacer = StringUtils.repeat("-", depth);
    log.debug("{}Key: {}, Children: {}", new Object[] { spacer, view.getName(), view.getChildren().size() });
    for (CategoryView child : view.getChildren().values()) {
        printMap(child, depth + 1);//  w  w  w  . j av  a 2 s .  c  o m
    }
}

From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java

@Test
public void testQueueLargeMessageSize() throws Exception {

    ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
    acf.setMinLargeMessageSize(1000);/*from ww  w.  j  av a  2  s .  c o m*/
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    String testText = StringUtils.repeat("t", 5000);
    ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
    session.createProducer(session.createQueue(defaultQueueName)).send(message);

    verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());

    connection.close();

    this.killServer();
    this.restartServer();

    verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());

}

From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java

@Test
public void testQueueLargeMessageSizeTX() throws Exception {

    ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
    acf.setMinLargeMessageSize(1000);//from  ww w .  j a va2  s . co m
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

    String testText = StringUtils.repeat("t", 2000);
    MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName));
    ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
    for (int i = 0; i < 10; i++) {
        producer.send(message);
    }

    //not commited so should be 0
    verifyPendingStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);
    verifyPendingDurableStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);

    session.commit();

    verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);
    verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);

    connection.close();

    this.killServer();
    this.restartServer();

    verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
}

From source file:org.apache.activemq.bugs.AMQ7067Test.java

@Test
public void testXAPrepare() throws Exception {

    setupXAConnection();//from   ww w .java2  s.c  o  m

    Queue holdKahaDb = xaSession.createQueue("holdKahaDb");

    MessageProducer holdKahaDbProducer = xaSession.createProducer(holdKahaDb);

    XATransactionId txid = createXATransaction();
    System.out.println("****** create new txid = " + txid);
    xaRes.start(txid, TMNOFLAGS);

    TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", 10));
    holdKahaDbProducer.send(helloMessage);
    xaRes.end(txid, TMSUCCESS);

    Queue queue = xaSession.createQueue("test");

    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    xaRes.prepare(txid);

    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return 0 == getQueueSize(queue.getQueueName());
        }
    });

    // force gc
    broker.getPersistenceAdapter().checkpoint(true);

    Xid[] xids = xaRes.recover(TMSTARTRSCAN);

    //Should be 1 since we have only 1 prepared
    assertEquals(1, xids.length);
    connection.close();

    broker.stop();
    broker.waitUntilStopped();
    createBroker();

    setupXAConnection();
    xids = xaRes.recover(TMSTARTRSCAN);

    System.out.println("****** recovered = " + xids);

    // THIS SHOULD NOT FAIL AS THERE SHOULD DBE ONLY 1 TRANSACTION!
    assertEquals(1, xids.length);
}

From source file:org.apache.activemq.bugs.AMQ7067Test.java

@Test
public void testXAPrepareWithAckCompactionDoesNotLooseInflight() throws Exception {

    // investigate liner gc issue - store usage not getting released
    org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);

    setupXAConnection();/*from  w w w  .j  a  va2s  .  com*/

    Queue holdKahaDb = xaSession.createQueue("holdKahaDb");

    MessageProducer holdKahaDbProducer = xaSession.createProducer(holdKahaDb);

    XATransactionId txid = createXATransaction();
    System.out.println("****** create new txid = " + txid);
    xaRes.start(txid, TMNOFLAGS);

    TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", 10));
    holdKahaDbProducer.send(helloMessage);
    xaRes.end(txid, TMSUCCESS);

    Queue queue = xaSession.createQueue("test");

    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    xaRes.prepare(txid);

    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return 0 == getQueueSize(queue.getQueueName());
        }
    });

    // force gc, two data files requires two cycles
    int limit = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getCompactAcksAfterNoGC() + 1;
    for (int i = 0; i < limit * 2; i++) {
        broker.getPersistenceAdapter().checkpoint(true);
    }

    // ack compaction task operates in the background
    TimeUnit.SECONDS.sleep(5);

    Xid[] xids = xaRes.recover(TMSTARTRSCAN);

    //Should be 1 since we have only 1 prepared
    assertEquals(1, xids.length);
    connection.close();

    broker.stop();
    broker.waitUntilStopped();
    createBroker();

    setupXAConnection();
    xids = xaRes.recover(TMSTARTRSCAN);

    System.out.println("****** recovered = " + xids);

    // THIS SHOULD NOT FAIL AS THERE SHOULD DBE ONLY 1 TRANSACTION!
    assertEquals(1, xids.length);
}

From source file:org.apache.activemq.bugs.AMQ7067Test.java

protected void doTestXACompletionWithAckCompactionDoesNotLooseOutcomeOnFullRecovery(boolean commit)
        throws Exception {

    ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).setCompactAcksAfterNoGC(2);
    // investigate liner gc issue - store usage not getting released
    org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);

    setupXAConnection();//from w  w  w .  java  2  s . c  om

    Queue holdKahaDb = xaSession.createQueue("holdKahaDb");

    MessageProducer holdKahaDbProducer = xaSession.createProducer(holdKahaDb);

    XATransactionId txid = createXATransaction();
    System.out.println("****** create new txid = " + txid);
    xaRes.start(txid, TMNOFLAGS);

    TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", 10));
    holdKahaDbProducer.send(helloMessage);
    xaRes.end(txid, TMSUCCESS);

    Queue queue = xaSession.createQueue("test");

    produce(xaRes, xaSession, queue, 100, 512 * 1024);
    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    xaRes.prepare(txid);

    // hold onto data file with prepare record
    produce(xaRes, xaSession, holdKahaDb, 1, 10);

    produce(xaRes, xaSession, queue, 50, 512 * 1024);
    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return 0 == getQueueSize(queue.getQueueName());
        }
    });

    if (commit) {
        xaRes.commit(txid, false);
    } else {
        xaRes.rollback(txid);
    }

    produce(xaRes, xaSession, queue, 50, 512 * 1024);
    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return 0 == getQueueSize(queue.getQueueName());
        }
    });

    int limit = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getCompactAcksAfterNoGC() + 1;
    // force gc, n data files requires n cycles
    for (int dataFilesToMove = 0; dataFilesToMove < 4; dataFilesToMove++) {
        for (int i = 0; i < limit; i++) {
            broker.getPersistenceAdapter().checkpoint(true);
        }
        // ack compaction task operates in the background
        TimeUnit.SECONDS.sleep(2);
    }

    Xid[] xids = xaRes.recover(TMSTARTRSCAN);

    //Should be 0 since we have delivered the outcome
    assertEquals(0, xids.length);
    connection.close();

    // need full recovery to see lost commit record
    curruptIndexFile(getDataDirectory());

    broker.stop();
    broker.waitUntilStopped();
    createBroker();

    setupXAConnection();
    xids = xaRes.recover(TMSTARTRSCAN);

    System.out.println("****** recovered = " + xids);

    assertEquals(0, xids.length);
}

From source file:org.apache.activemq.bugs.AMQ7067Test.java

@Test
public void testXAcommit() throws Exception {

    setupXAConnection();/*from  ww w .  j a  v  a2 s.c  om*/

    Queue holdKahaDb = xaSession.createQueue("holdKahaDb");
    createDanglingTransaction(xaRes, xaSession, holdKahaDb);

    MessageProducer holdKahaDbProducer = xaSession.createProducer(holdKahaDb);

    XATransactionId txid = createXATransaction();
    System.out.println("****** create new txid = " + txid);
    xaRes.start(txid, TMNOFLAGS);

    TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", 10));
    holdKahaDbProducer.send(helloMessage);
    xaRes.end(txid, TMSUCCESS);
    xaRes.prepare(txid);

    Queue queue = xaSession.createQueue("test");

    produce(xaRes, xaSession, queue, 100, 512 * 1024);
    xaRes.commit(txid, false);
    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return 0 == getQueueSize(queue.getQueueName());
        }
    });

    // force gc
    broker.getPersistenceAdapter().checkpoint(true);

    Xid[] xids = xaRes.recover(TMSTARTRSCAN);

    //Should be 1 since we have only 1 prepared
    assertEquals(1, xids.length);
    connection.close();

    broker.stop();
    broker.waitUntilStopped();
    createBroker();

    setupXAConnection();
    xids = xaRes.recover(TMSTARTRSCAN);

    // THIS SHOULD NOT FAIL AS THERE SHOULD DBE ONLY 1 TRANSACTION!
    assertEquals(1, xids.length);

}

From source file:org.apache.activemq.bugs.AMQ7067Test.java

@Test
public void testXArollback() throws Exception {

    setupXAConnection();/*  w  w w .jav  a 2 s.com*/

    Queue holdKahaDb = xaSession.createQueue("holdKahaDb");
    createDanglingTransaction(xaRes, xaSession, holdKahaDb);

    MessageProducer holdKahaDbProducer = xaSession.createProducer(holdKahaDb);

    XATransactionId txid = createXATransaction();
    System.out.println("****** create new txid = " + txid);
    xaRes.start(txid, TMNOFLAGS);

    TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", 10));
    holdKahaDbProducer.send(helloMessage);
    xaRes.end(txid, TMSUCCESS);
    xaRes.prepare(txid);

    Queue queue = xaSession.createQueue("test");

    produce(xaRes, xaSession, queue, 100, 512 * 1024);
    xaRes.rollback(txid);
    produce(xaRes, xaSession, queue, 100, 512 * 1024);

    ((org.apache.activemq.broker.region.Queue) broker.getRegionBroker().getDestinationMap().get(queue)).purge();

    Xid[] xids = xaRes.recover(TMSTARTRSCAN);

    //Should be 1 since we have only 1 prepared
    assertEquals(1, xids.length);
    connection.close();

    broker.stop();
    broker.waitUntilStopped();
    createBroker();

    setupXAConnection();
    xids = xaRes.recover(TMSTARTRSCAN);

    // THIS SHOULD NOT FAIL AS THERE SHOULD BE ONLY 1 TRANSACTION!
    assertEquals(1, xids.length);

}