List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
From source file:org.apache.parquet.cli.commands.ParquetMetadataCommand.java
private void printRowGroup(Logger console, int index, BlockMetaData rowGroup, MessageType schema) { long start = rowGroup.getStartingPos(); long rowCount = rowGroup.getRowCount(); long compressedSize = rowGroup.getCompressedSize(); long uncompressedSize = rowGroup.getTotalByteSize(); String filePath = rowGroup.getPath(); console.info(String.format("\nRow group %d: count: %d %s records start: %d total: %s%s\n%s", index, rowCount, humanReadable(((float) compressedSize) / rowCount), start, humanReadable(compressedSize), filePath != null ? " path: " + filePath : "", StringUtils.leftPad("", 80, '-'))); int size = maxSize(Iterables.transform(rowGroup.getColumns(), new Function<ColumnChunkMetaData, String>() { @Override/*from w w w. j ava 2s. c om*/ public String apply(@Nullable ColumnChunkMetaData input) { return input == null ? "" : input.getPath().toDotString(); } })); console.info(String.format("%-" + size + "s %-9s %-9s %-9s %-10s %-7s %s", "", "type", "encodings", "count", "avg size", "nulls", "min / max")); for (ColumnChunkMetaData column : rowGroup.getColumns()) { printColumnChunk(console, size, column, schema); } }
From source file:org.apache.parquet.cli.commands.ShowPagesCommand.java
@Override @SuppressWarnings("unchecked") public int run() throws IOException { Preconditions.checkArgument(targets != null && targets.size() >= 1, "A Parquet file is required."); Preconditions.checkArgument(targets.size() == 1, "Cannot process multiple Parquet files."); String source = targets.get(0); ParquetFileReader reader = ParquetFileReader.open(getConf(), qualifiedPath(source)); MessageType schema = reader.getFileMetaData().getSchema(); Map<ColumnDescriptor, PrimitiveType> columns = Maps.newLinkedHashMap(); if (this.columns == null || this.columns.isEmpty()) { for (ColumnDescriptor descriptor : schema.getColumns()) { columns.put(descriptor, primitive(schema, descriptor.getPath())); }// w w w . ja v a2s. c om } else { for (String column : this.columns) { columns.put(descriptor(column, schema), primitive(column, schema)); } } CompressionCodecName codec = reader.getRowGroups().get(0).getColumns().get(0).getCodec(); // accumulate formatted lines to print by column Map<String, List<String>> formatted = Maps.newLinkedHashMap(); PageFormatter formatter = new PageFormatter(); PageReadStore pageStore; int rowGroupNum = 0; while ((pageStore = reader.readNextRowGroup()) != null) { for (ColumnDescriptor descriptor : columns.keySet()) { List<String> lines = formatted.get(columnName(descriptor)); if (lines == null) { lines = Lists.newArrayList(); formatted.put(columnName(descriptor), lines); } formatter.setContext(rowGroupNum, columns.get(descriptor), codec); PageReader pages = pageStore.getPageReader(descriptor); DictionaryPage dict = pages.readDictionaryPage(); if (dict != null) { lines.add(formatter.format(dict)); } DataPage page; while ((page = pages.readPage()) != null) { lines.add(formatter.format(page)); } } rowGroupNum += 1; } // TODO: Show total column size and overall size per value in the column summary line for (String columnName : formatted.keySet()) { console.info(String.format("\nColumn: %s\n%s", columnName, StringUtils.leftPad("", 80, '-'))); console.info(formatter.getHeader()); for (String line : formatted.get(columnName)) { console.info(line); } console.info(""); } return 0; }
From source file:org.apache.synapse.transport.udp.Utils.java
public static void hexDump(StringBuilder buffer, byte[] data, int length) { for (int start = 0; start < length; start += 16) { for (int i = 0; i < 16; i++) { int index = start + i; if (index < length) { buffer.append(StringUtils.leftPad(Integer.toHexString(data[start + i]), 2, '0')); } else { buffer.append(" "); }/*from w ww . j a v a 2 s . c o m*/ buffer.append(' '); if (i == 8) { buffer.append(' '); } } buffer.append(" |"); for (int i = 0; i < 16; i++) { int index = start + i; if (index < length) { int b = data[index] & 0xFF; if (32 <= b && b < 128) { buffer.append((char) b); } else { buffer.append('.'); } } else { buffer.append(' '); } } buffer.append('|'); buffer.append('\n'); } }
From source file:org.apache.tajo.engine.function.string.Lpad.java
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) { return NullDatum.get(); }//from ww w . j a v a 2 s . com String fillText; if (hasFillCharacters) { fillText = params.getText(2); } else { fillText = " "; } String input = params.getText(0); int expected = params.getInt4(1); int templen = expected - params.size(0); if (templen <= 0) { return DatumFactory.createText(input.substring(0, expected)); } else { return DatumFactory.createText(StringUtils.leftPad(input, expected, fillText)); } }
From source file:org.apache.tika.parser.wordperfect.WPInputStream.java
/** * Reads the next byte and returns it as an hexadecimal value. * @return hexadecimal string for a single byte * @throws IOException if not enough bytes remain *//*from www. j av a 2 s . c om*/ public String readWPHex() throws IOException { return StringUtils.leftPad(Integer.toString(readWP(), 16), 2, '0'); }
From source file:org.beangle.ems.security.nav.service.MenuServiceImpl.java
private void shiftCode(Menu menu, Menu newParent, int indexno) { List<Menu> sibling = null; if (null != newParent) sibling = newParent.getChildren(); else {//from w w w. jav a 2 s. c om sibling = CollectUtils.newArrayList(); for (Menu m : menu.getProfile().getMenus()) { if (null == m.getParent()) sibling.add(m); } } Collections.sort(sibling); sibling.remove(menu); indexno--; if (indexno > sibling.size()) { indexno = sibling.size(); } sibling.add(indexno, menu); int nolength = String.valueOf(sibling.size()).length(); Set<Menu> menus = CollectUtils.newHashSet(); for (int seqno = 1; seqno <= sibling.size(); seqno++) { Menu one = sibling.get(seqno - 1); generateCode(one, StringUtils.leftPad(String.valueOf(seqno), nolength, '0'), menus); } entityDao.saveOrUpdate(menus); }
From source file:org.beangle.website.system.service.impl.DictTreeServiceImpl.java
private void shiftCode(DictTree menu, DictTree newParent, int indexno) { List<DictTree> sibling = null; if (null != newParent) { sibling = newParent.getChildren(); } else {//from w w w .j ava 2 s . co m sibling = CollectUtils.newArrayList(); OqlBuilder<DictTree> query = OqlBuilder.from(DictTree.class); query.where("parent is null"); sibling = entityDao.search(query); } Collections.sort(sibling); sibling.remove(menu); indexno--; if (indexno > sibling.size()) { indexno = sibling.size(); } sibling.add(indexno, menu); int nolength = String.valueOf(sibling.size()).length(); Set<DictTree> menus = CollectUtils.newHashSet(); for (int seqno = 1; seqno <= sibling.size(); seqno++) { DictTree one = sibling.get(seqno - 1); generateCode(one, StringUtils.leftPad(String.valueOf(seqno), nolength, '0'), menus); } entityDao.saveOrUpdate(menus); }
From source file:org.bigmouth.nvwa.utils.SerializedUtils.java
public static String generate() { long tmp = 1; synchronized (object2) { seed2++;/*from w w w.j a va2 s . co m*/ if (seed2 > 999999999999999l) { try { Thread.sleep(1000); } catch (InterruptedException e) { ; } seed2 = 1; } tmp = seed2; } return DateUtils.getCurrentStringDate("yyyyMMddHHmmssSSS") + StringUtils.leftPad(String.valueOf(tmp), 15, "0"); }
From source file:org.bimserver.database.migrations.Migrator.java
@SuppressWarnings("unchecked") private Migration getMigration(int number) { String name = "org.bimserver.database.migrations.steps.Step" + StringUtils.leftPad("" + number, 4, "0"); try {/* w w w .ja va 2 s. c o m*/ Class<Migration> migrationClass = (Class<Migration>) Class.forName(name); return migrationClass.newInstance(); } catch (Exception e) { if (e instanceof ClassNotFoundException) { // ignore } else { LOGGER.error("", e); } return null; } }
From source file:org.codehaus.groovy.grails.plugins.codecs.JSONEncoder.java
@Override protected String escapeCharacter(char ch, char previousChar) { switch (ch) { case '"': return "\\\""; case '\\': return "\\\\"; case '\t': return "\\t"; case '\n': return "\\n"; case '\r': return "\\r"; case '\f': return "\\f"; case '\b': return "\\b"; case '\u000B': // vertical tab: http://bclary.com/2004/11/07/#a-7.8.4 return "\\v"; case '\u2028': return "\\u2028"; // Line separator case '\u2029': return "\\u2029"; // Paragraph separator case '/': // preserve special handling that exists in JSONObject.quote to improve security if JSON is embedded in HTML document // prevents outputting "</" gets outputted with unicode escaping for the slash if (previousChar == '<') { return "\\u002f"; }/*from ww w . j a v a 2 s. c o m*/ break; } if (ch < ' ') { // escape all other control characters return "\\u" + StringUtils.leftPad(Integer.toHexString(ch), 4, '0'); } return null; }