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:ext.services.xml.TestXMLUtils.java

/**
 * Test get document parse error./*  ww w . j av a 2  s  .c  om*/
 * 
 */
public void testGetDocumentParseError() {
    Document doc = XMLUtils.getDocument("<xmlinvalid>adsasd<asdksdtest value=\"1\"/></xml>");
    assertNull(doc);
    doc = XMLUtils.getDocument(StringUtils.repeat("1", 1000)); // more than 500
    // characters for
    // log.debug
    assertNull(doc);
}

From source file:com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.java

/**
 * Initialize dispatcher servlet//from ww w.  j  a v  a 2s  .  c  o m
 *
 * @param config ServletConfig
 */
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    if (JiraStartupChecklist.startupOK()) {
        // Clear caches
        // RO: If not, then it will contain garbage after a couple of redeployments
        Introspector.flushCaches();

        // Clear ValueStack method cache
        // RO: If not, then it will contain garbage after a couple of redeployments
        ValueStack.clearMethods();

        // Find the save dir, which should be the servlet context temp directory
        // Use the default - the Servlet Context Temp Directory.
        File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir");
        if (tempdir != null) {
            saveDir = tempdir.getAbsolutePath();
        } else {
            log.error("Servlet Context Temp Directory isn't set. No save directory set for file uploads.");
        }
        log.info("Setting Upload File Directory to '{}'", saveDir);
        log.info("JiraWebworkActionDispatcher initialized");
    } else {
        // JIRA startup not OK
        String message = "JIRA startup failed, JIRA has been locked.";
        String line = StringUtils.repeat("*", message.length());
        log.error(NEW_LINE + NEW_LINE + line + NEW_LINE + message + NEW_LINE + line + NEW_LINE);
    }
}

From source file:com.netprogs.minecraft.plugins.social.command.util.MessageUtil.java

public static void sendFooterLinesOnly(CommandSender receiver) {

    ChatColor SPACER_COLOR = ChatColor.YELLOW;
    String displayFooter = StringUtils.repeat("-", 50);

    receiver.sendMessage(SPACER_COLOR + displayFooter);
}

From source file:de.csdev.ebus.utils.EBusConsoleUtils.java

/**
 * Returns telegram analyze data//  www  . jav a 2  s . c o  m
 *
 * @param registry
 * @param data
 * @return
 */
public static String analyzeTelegram(EBusCommandRegistry registry, byte[] data) {

    StringBuilder sb = new StringBuilder();
    try {
        byte[] edata = null;

        sb.append("\n");

        try {
            edata = EBusCommandUtils.checkRawTelegram(data);
        } catch (EBusDataException e) {

            String msg = String.format("** Error on checking telegram: %s **", e.getMessage());
            int len = msg.length();

            sb.append("\n");
            sb.append(StringUtils.repeat("*", len) + "\n");
            sb.append(msg + "\n");

            msg = "**     !!! Warning: All following results are wrong and only displayed for information purpose !!!";
            msg += StringUtils.repeat(" ", len - msg.length() - 2) + "**";

            sb.append(msg + "\n");
            sb.append(StringUtils.repeat("*", len) + "\n");
            sb.append("\n");

            return sb.toString();
        }

        sb.append("\n");
        sb.append("Check and unescape telegram\n");
        sb.append("***************************\n");
        sb.append("\n");

        sb.append(String.format("Original data : %s\n", EBusUtils.toHexDumpString(data)));
        sb.append(String.format("Unescaped data: %s\n", EBusUtils.toHexDumpString(edata)));

        byte[] command = Arrays.copyOfRange(edata, 2, 4);

        boolean isMasterMaster = EBusUtils.isMasterAddress(edata[1]);
        boolean isBroadcast = edata[1] == EBusConsts.BROADCAST_ADDRESS;
        boolean isMasterSlave = !isMasterMaster && !isBroadcast;

        int masterDataLenPos = 4;
        int masterDataLen = edata[masterDataLenPos];
        byte[] masterData = Arrays.copyOfRange(edata, 5, 5 + masterDataLen);

        int masterCrcPos = 5 + masterDataLen;
        int slaveACKPos = masterCrcPos + 1;

        String dataString = EBusUtils.toHexDumpString(edata).toString();
        int dataLen = dataString.length();

        sb.append("\n");
        sb.append("Analyse the telegram\n");
        sb.append("********************\n");

        sb.append("\n");
        sb.append(dataString + "\n");

        final String FORMAT = "%-20s | %-20s | %s";

        sb.append(createTelegramResoverRow(0, 1, dataLen,
                String.format(FORMAT, "Source address", "Type: " + addressType(edata[0]), hex(edata[0]))));

        sb.append(createTelegramResoverRow(1, 1, dataLen,
                String.format(FORMAT, "Destination address", "Type: " + addressType(edata[1]), hex(edata[1]))));

        sb.append(createTelegramResoverRow(2, 2, dataLen, String.format(FORMAT, "Command", "", hex(command))));

        sb.append(createTelegramResoverRow(4, 1, dataLen,
                String.format(FORMAT, "Master Data Length", "Length: " + edata[4], hex(edata[4]))));

        sb.append(createTelegramResoverRow(5, masterDataLen, dataLen,
                String.format(FORMAT, "Master Data", "", hex(masterData))));

        sb.append(createTelegramResoverRow(masterCrcPos, 1, dataLen,
                String.format(FORMAT, "Master CRC", "", hex(edata[masterCrcPos]))));

        if (isMasterMaster) {
            sb.append(
                    createTelegramResoverRow(slaveACKPos, 1, dataLen, hex(edata[slaveACKPos]) + " Slave ACK"));
            // SYN

        } else if (isBroadcast) {
            // SYN

        } else if (isMasterSlave) {

            int slaveDataLenPos = slaveACKPos + 1;
            int slaveDataLen = edata[slaveDataLenPos];

            int slaveDataPos = slaveDataLenPos + 1;
            int slaveCRCPos = slaveDataPos + slaveDataLen;

            int masterACKPos = slaveCRCPos + 1;

            byte[] slaveData = Arrays.copyOfRange(edata, slaveDataPos, slaveDataPos + slaveDataLen);

            sb.append(createTelegramResoverRow(slaveACKPos, 1, dataLen,
                    String.format(FORMAT, "Slave ACK", "", hex(edata[slaveACKPos]))));

            sb.append(createTelegramResoverRow(slaveDataLenPos, 1, dataLen, String.format(FORMAT,
                    "Slave Data Length", "Length: " + edata[slaveDataLenPos], hex(edata[slaveDataLenPos]))));

            sb.append(createTelegramResoverRow(slaveDataPos, slaveDataLen, dataLen,
                    String.format(FORMAT, "Slave Data", "", hex(slaveData))));

            sb.append(createTelegramResoverRow(slaveCRCPos, 1, dataLen,
                    String.format(FORMAT, "Slave CRC", "", hex(edata[slaveCRCPos]))));

            sb.append(createTelegramResoverRow(masterACKPos, 1, dataLen,
                    String.format(FORMAT, "Master ACK", "", hex(edata[masterACKPos]))));

        }

        List<IEBusCommandMethod> methods = registry.find(edata);

        sb.append("\n");
        sb.append("Resolve the telegram\n");
        sb.append("********************\n");
        sb.append("\n");
        sb.append(String.format("Found %s command method(s) for this telegram.\n", methods.size()));
        sb.append("\n");

        for (IEBusCommandMethod method : methods) {
            try {
                Map<String, Object> result = EBusCommandUtils.decodeTelegram(method, data);

                sb.append(String.format("Values from command '%s' with method '%s' from collection '%s'\n",
                        method.getParent().getId(), method.getMethod(),
                        method.getParent().getParentCollection().getId()));

                for (Entry<String, Object> entry : result.entrySet()) {
                    Object value = entry.getValue();

                    if (value instanceof byte[]) {
                        value = EBusUtils.toHexDumpString((byte[]) value);
                    }

                    sb.append(String.format("  %-20s = %s\n", entry.getKey(),
                            value != null ? value.toString() : "NULL"));
                }

            } catch (EBusTypeException e) {
                logger.error("error!", e);
            }
        }
        sb.append("\n");
    } catch (Exception e) {
        logger.error("error!", e);
    }

    return sb.toString();

}

From source file:elaborate.editor.export.mvn.MVNTranscriptionVisitor.java

private static String indent() {
    return StringUtils.repeat(" ", indent * 2);
}

From source file:com.google.api.ads.dfp.lib.utils.v201208.PqlUtils.java

/**
 * Creates the row seperator given the maximum size for each column
 *
 * @param maxColumnSizes the maximum size for each column
 * @return the row seperator/*from w  ww. j av  a  2s.  com*/
 */
private static String createRowSeperator(List<Integer> maxColumnSizes) {
    StringBuilder rowSeperator = new StringBuilder("+");
    for (int maxColumnSize : maxColumnSizes) {
        rowSeperator.append(StringUtils.repeat("-", maxColumnSize + 2)).append("+");
    }
    return rowSeperator.append("\n").toString();
}

From source file:dk.netarkivet.harvester.harvesting.metadata.MetadataFileWriterTester.java

/**
 * This is not run automatically, as this takes a long time to complete (15 seconds).
 *//*from  w  w  w.  j  av a 2  s .c o m*/
@Category(SlowTest.class)
@Test
public void notestMetadataFileWriterWarcMassiveLoadTest() throws IOException {
    // TODO verify content of produced warc-file to ensure that all is OK
    File metafile = getOutputArcFile("metadata.warc");
    MetadataFileWriterWarc mdfw = (MetadataFileWriterWarc) MetadataFileWriterWarc.createWriter(metafile);
    mdfw.insertInfoRecord(new ANVLRecord());
    // Create 5000 small files
    String contentPart = "blablabla";
    String someText = StringUtils.repeat(contentPart, 5000);
    List textArray = new ArrayList<String>();
    textArray.add(someText);
    Set<File> files = new HashSet<>();
    for (int i = 0; i < 10000; i++) {
        File f = File.createTempFile("metadata", "cdx");
        FileUtils.writeCollectionToFile(f, textArray);
        files.add(f);
    }
    int count = 0;
    for (File f : files) {
        mdfw.writeFileTo(f, "http://netarkivet/ressource-" + count, "text/plain");
        f.delete();
        count++;
    }
}

From source file:com.logsniffer.reader.support.BackwardReaderTest.java

@Test
public void testRecursionBug() throws FormatException, UnsupportedEncodingException, IOException {
    log = Log4jTextReaderTest.createLog(0, StringUtils.repeat(StringUtils.repeat("abc", 72) + "\n", 1000));
    final Log4jTextReader log4jReader = new Log4jTextReader("unknown format", "UTF-8");
    log4jReader.setMaxUnfomattedLines(1);
    final BackwardReader<ByteLogAccess> reader = new BackwardReader<ByteLogAccess>(log4jReader);
    final List<LogEntry> entries = reader.readEntries(log, log, log.createRelative(null, 52000), -100);
    Assert.assertEquals(100, entries.size());
}

From source file:adalid.core.ViewField.java

@Override
protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.fieldsToString(n, key, verbose, fields, maps);
    if (fields || verbose) {
        if (verbose) {
            String column = _column == null ? "" : _column.getName();
            string += fee + tab + "column" + faa + column + foo;
        }//www  .j a  va 2 s. co m
    }
    return string;
}

From source file:com.opengamma.component.ComponentConfigPropertiesLoader.java

/**
 * Handle the inclusion of another file.
 * //from   w  w  w.j  a  va2 s.  com
 * @param baseResource  the base resource, not null
 * @param includeFile  the resource to include, not null
 * @param depth  the depth of the properties file, used for logging
 */
private void handleInclude(final Resource baseResource, String includeFile, final int depth) {
    // find resource
    Resource include;
    try {
        include = ResourceUtils.createResource(includeFile);
    } catch (Exception ex) {
        try {
            include = baseResource.createRelative(includeFile);
        } catch (Exception ex2) {
            throw new OpenGammaRuntimeException(ex2.getMessage(), ex2);
        }
    }

    // load and merge
    getLogger().logInfo(
            StringUtils.repeat(" ", depth) + "   Including item: " + ResourceUtils.getLocation(include));
    load(include, depth + 1);
}