List of usage examples for org.apache.commons.lang3 StringUtils rightPad
public static String rightPad(final String str, final int size, String padStr)
Right pad a String with a specified String.
The String is padded to the size of size .
StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, "z") = "zzz" StringUtils.rightPad("bat", 3, "yz") = "bat" StringUtils.rightPad("bat", 5, "yz") = "batyz" StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" StringUtils.rightPad("bat", 1, "yz") = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null) = "bat " StringUtils.rightPad("bat", 5, "") = "bat "
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceTest.java
private void createLongConfigSetContent(int size, boolean testPersistence) throws BusinessException { String frontEndConfigSetContent = "#Comment too long ?"; frontEndConfigSetContent = StringUtils.rightPad(frontEndConfigSetContent, size, '?'); createConfigSetLogicalModelCatalog(frontEndConfigSetContent, testPersistence); }
From source file:edu.kit.dama.ui.admin.wizard.BaseMetadataExtractionAndIndexingCreation.java
@Override public String getSummary() { StringBuilder result = new StringBuilder(); result.append(getStepName()).append("\n"); result.append(StringUtils.rightPad("", 50, "_")).append("\n"); if (createMetsExtractor.getValue()) { result.append("Create METS Extractor: ").append((createMetsExtractor.getValue()) ? "yes\n" : "no\n"); Set<Entry<String, TextField>> entries = extractorProperties.entrySet(); result.append("Properties:\n"); entries.forEach((entry) -> {/*from ww w . ja va 2 s. c om*/ result.append(entry.getKey()).append(": ").append(entry.getValue().getValue()).append("\n"); }); } else { result.append("No metadata extractor will be created.\n"); } return result.toString(); }
From source file:br.usp.poli.lta.cereda.macro.ui.Editor.java
/** * Construtor./*w ww . jav a 2 s. c o m*/ */ public Editor() { // define as configuraes de exibio super("Expansor de macros"); setPreferredSize(new Dimension(550, 550)); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false); setLayout(new MigLayout()); // cria os botes e suas respectivas aes open = new JButton("Abrir", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/open.png"))); save = new JButton("Salvar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/save.png"))); run = new JButton("Executar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/play.png"))); clear = new JButton("Limpar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/clear.png"))); // cria uma janela de dilogo para abrir e salvar arquivos de texto chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivos de texto", "txt", "text"); chooser.setFileFilter(filter); // ao de abertura de arquivo open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showOpenDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { String content = FileUtils.readFileToString(file); input.setText(content); output.setText(""); } catch (Exception e) { } } } }); // ao de salvamento de arquivo save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showSaveDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { FileUtils.writeStringToFile(file, input.getText(), Charset.forName("UTF-8")); output.setText(""); } catch (Exception e) { } } } }); // ao de limpeza da janela de sada clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { output.setText(""); } }); // ao de execuo do expansor de macros run.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { output.setText(MacroExpander.parse(input.getText())); } catch (Exception exception) { String out = StringUtils.rightPad("ERRO: ", 50, "-").concat("\n"); out = out.concat(WordUtils.wrap(exception.getMessage(), 50)).concat("\n"); out = out.concat(StringUtils.repeat(".", 50)).concat("\n"); output.setText(out); } } }); // tela de entrada do texto input = new RSyntaxTextArea(14, 60); input.setCodeFoldingEnabled(true); input.setWrapStyleWord(true); input.setLineWrap(true); RTextScrollPane iinput = new RTextScrollPane(input); add(iinput, "span 4, wrap"); // adiciona os botes add(open); add(save); add(run); add(clear, "wrap"); // tela de sada da expanso output = new RSyntaxTextArea(14, 60); output.setEditable(false); output.setCodeFoldingEnabled(true); output.setWrapStyleWord(true); output.setLineWrap(true); RTextScrollPane ioutput = new RTextScrollPane(output); add(ioutput, "span 4"); // ajustes finais pack(); setLocationRelativeTo(null); }
From source file:au.com.addstar.SpigotUpdater.java
private static UpdateCallback getUpdateCallBack(SpigetUpdater updater, Plugin p, boolean check) { return new UpdateCallback() { @Override//from ww w . ja va2 s .c o m public void updateAvailable(ResourceInfo latestResource, String url, boolean hasDirectDownload) { String name = StringUtils.rightPad(p.getName(), 25, " "); Console.Color resouceColor = null; if (latestResource.premium) { resouceColor = Console.Color.ANSI_YELLOW; } List<String> out = new ArrayList<>(); out.add(Console.wrap(name, resouceColor)); out.add(StringUtils.rightPad(p.getResourceID().toString(), 7)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(StringUtils.truncate(StringUtils.rightPad(latestResource.latestVersion.name, 10), 10)); if ((hasDirectDownload || externalDownloads) && !check) { String result; Console.Color color; if (updater.downloadUpdate(p)) { result = "DONE"; color = Console.Color.ANSI_GREEN; } else { result = "FAIL"; color = Console.Color.ANSI_RED; } out.add(Console.wrap(StringUtils.rightPad(result, 7), color)); out.add(StringUtils.rightPad(format.format(p.getLastUpdated()), 10)); if (result.equals("FAIL")) out.add(" REASON: " + updater.getFailReason() + " - URL: " + url); } else { out.add(Console.wrapPad("NO", Console.Color.ANSI_RED, 7)); Console.Color dateColor = null; Date lastUpdate = p.getLastUpdated(); long diff = new Date().getTime() - lastUpdate.getTime(); if (diff > 0) { diff = diff / (60 * 60 * 1000); dateColor = Console.Color.ANSI_BLACK_RED; if (diff < 24) dateColor = Console.Color.ANSI_GREEN; if (diff < 72) dateColor = Console.Color.ANSI_YELLOW; if (diff < 144) dateColor = Console.Color.ANSI_RED; } out.add(Console.wrapPad(format.format(p.getLastUpdated()), dateColor, 10)); out.add(" URL: " + url); } StringBuilder sb = new StringBuilder(); String[] message = new String[out.size()]; out.toArray(message); sb.append(StringUtils.join(message, " | " + Console.Color.ANSI_RESET)); System.out.println(sb.toString()); } @Override public void upToDate() { String name = StringUtils.rightPad(p.getName(), 25, " "); List<String> out = new ArrayList<>(); out.add(name); out.add(StringUtils.rightPad(p.getResourceID().toString(), 7)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(Console.wrap(StringUtils.rightPad("YES", 7), Console.Color.ANSI_GREEN)); out.add(StringUtils.rightPad(format.format(p.getLastUpdated()), 10)); StringBuilder sb = new StringBuilder(); String[] message = new String[out.size()]; out.toArray(message); sb.append(StringUtils.join(message, " | ")); System.out.println(sb.toString()); } }; }
From source file:edu.kit.dama.ui.admin.wizard.AdministratorAccountCreation.java
@Override public String getSummary() { StringBuilder result = new StringBuilder(); result.append(getStepName()).append("\n"); result.append(StringUtils.rightPad("", 50, "_")).append("\n"); result.append("Administrator First Name: ").append(adminFirstName.getValue()).append("\n"); result.append("Administrator Last Name: ").append(adminLastName.getValue()).append("\n"); result.append("Administrator EMail: ").append(adminEMail.getValue()).append("\n"); result.append("Web Login Password: ").append(adminPassword.getValue()).append("\n"); result.append("Create OAuth access: ").append((addOAuthCredentials.getValue()) ? "yes\n" : "no\n"); if (addOAuthCredentials.getValue()) { result.append(" OAuth Key: ").append(oAuthKey).append("\n"); result.append(" OAuth Secret: ").append(oAuthSecret).append("\n"); }/*w ww . j a v a2s.c om*/ return result.toString(); }
From source file:com.netflix.imfutility.ttmltostl.stl.StlTtiTest.java
@Test public void testEbnBlocksForLongSubtitle() throws Exception { // prepare long subtitles, so that one subtitles is stored in two tti blocks TimedTextObject tto = StlTestUtil.buildTto("10:00:00:00", "10:00:05:00", StringUtils.rightPad("", 200, '1'), // in 2 tti "10:00:10:00", "10:01:10:00", StringUtils.rightPad("", 400, '2') // in 4 tti );// ww w . j av a 2 s .c o m byte[][] stl = StlTestUtil.build(tto, StlTestUtil.getMetadataXml()); byte[] tti = stl[1]; // 1st subtitle 1st block int offset = 128; // zero subtitle; assertArrayEquals(new byte[] { 0x01, 0x00, // subtitle number - 1 (byte) 0x00, // extension block - 1st 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x00, 0x00, // code in: 10:00:00:00 0x0a, 0x00, 0x05, 0x00, // code out: 10:00:05:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); // 1st subtitle 2d block offset += 128; assertArrayEquals(new byte[] { 0x01, 0x00, // subtitle number - 1 (byte) 0xff, // extension block - last 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x00, 0x00, // code in: 10:00:00:00 0x0a, 0x00, 0x05, 0x00, // code out: 10:00:05:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); // 2d subtitle 1st block offset += 128; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0x00, // extension block - 1st 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x0a, 0x00, // code in: 10:00:10:00 0x0a, 0x01, 0x0a, 0x00, // code out: 10:01:10:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); // 2d subtitle 2d block offset += 128; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0x01, // extension block - 2d 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x0a, 0x00, // code in: 10:00:10:00 0x0a, 0x01, 0x0a, 0x00, // code out: 10:01:10:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); // 2d subtitle 3d block offset += 128; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0x02, // extension block - 3d 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x0a, 0x00, // code in: 10:00:10:00 0x0a, 0x01, 0x0a, 0x00, // code out: 10:01:10:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); // 2d subtitle 4th block offset += 128; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0xff, // extension block - last 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x0a, 0x00, // code in: 10:00:10:00 0x0a, 0x01, 0x0a, 0x00, // code out: 10:01:10:00 0x16 // vertical position }, Arrays.copyOfRange(tti, offset + 1, offset + 14)); }
From source file:com.rvantwisk.gcodegenerator.dialects.RS274.java
/** * Create a decimal formatter to format the words * * @param numDecimals//from w w w . j a va 2s.com * @param stripZeros * @return */ private DecimalFormat getDecimalFormat(Integer numDecimals, final boolean stripZeros) { if (numDecimals == null) { numDecimals = 4; } String padder = "0"; if (stripZeros) { padder = "#"; } final String format = StringUtils.rightPad("#.", numDecimals + 2, padder); return new DecimalFormat(format); }
From source file:com.github.igor_kudryashov.utils.notes.NotesTempFile.java
/** * Returns a temporary file and stores it name in the store ~ notetmp.reg * //from w w w. ja v a 2 s . co m * @param postfix * - postfix of temporary filename. * @return the temporary file. */ public File getTempFile(String postfix) { File file = null; String p = postfix; try { if (p == null) { p = ".tmp"; } else { if (!p.startsWith(".")) { p = "." + p; } } file = File.createTempFile("~$0", p, new File(tempFolder)); // add filename to store File storeFile = new File(tempFolder + File.separator + NOTES_TMP_FILENAME); String filename = file.getName(); String fixfilename = StringUtils.rightPad(filename, 257, '\0'); FileWriter fw = new FileWriter(storeFile, true); fw.write(fixfilename); fw.close(); } catch (IOException e) { e.printStackTrace(); } return file; }
From source file:edu.kit.dama.ui.admin.wizard.AccessPointCreation.java
@Override public String getSummary() { StringBuilder result = new StringBuilder(); result.append(getStepName()).append("\n"); result.append(StringUtils.rightPad("", 50, "_")).append("\n"); if (addWebDavAccessPoint.getValue()) { result.append("Access Point Name: ").append(accessPointName.getValue()).append("\n"); result.append("Base Url: ").append(baseUrl.getValue()).append("\n"); result.append("Base Path: ").append(basePath.getValue()).append("\n"); result.append("Create Administrator Webdav Login: ") .append((createAdminLogin.getValue()) ? "yes\n" : "no\n"); if (createAdminLogin.getValue()) { result.append(" Webdav Login Name: ").append("<Administrator EMail>\n"); result.append(" Webdav Login Password: ").append(adminPassword.getValue()).append("\n"); }//ww w . ja v a2 s.c om } else { result.append("No WebDav Access Point will be created.\n"); } return result.toString(); }
From source file:com.splicemachine.triggers.Trigger_Create_IT.java
@Test public void create_illegal_triggerNameTooLong() throws Exception { String triggerNameOk = StringUtils.rightPad("trigNameOk", 128, 'x'); String triggerNameBad = StringUtils.rightPad("trigNameBad", 129, 'x'); try {//w ww . j a v a 2 s . c o m createTrigger( tb.on("T").named(triggerNameOk).after().update().statement().then("INSERT INTO R VALUES(1)")); createTrigger( tb.on("T").named(triggerNameBad).after().update().statement().then("INSERT INTO R VALUES(1)")); fail("didn't expect to be able to crate a trigger with a name longer than 128"); } catch (SQLException e) { assertEquals( "The name '" + triggerNameBad.toUpperCase() + "' is too long. The maximum length is '128'.", e.getMessage()); } }