List of usage examples for org.apache.commons.lang3 StringUtils leftPad
public static String leftPad(final String str, final int size, String padStr)
Left pad a String with a specified String.
Pad to a size of size .
StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, "z") = "zzz" StringUtils.leftPad("bat", 3, "yz") = "bat" StringUtils.leftPad("bat", 5, "yz") = "yzbat" StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" StringUtils.leftPad("bat", 1, "yz") = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null) = " bat" StringUtils.leftPad("bat", 5, "") = " bat"
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String toHex(byte[] bs) { StringBuilder sb = new StringBuilder(bs.length * 2); for (byte b : bs) sb.append(StringUtils.leftPad(Integer.toHexString(b & 0xff), 2, '0')); return sb.toString(); }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String toHex(byte b) { return StringUtils.leftPad(Integer.toHexString(b & 0xff), 2, '0'); }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String toHex(short s) { return StringUtils.leftPad(Integer.toHexString(s & 0xffff), 4, '0'); }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String toHex(int i) { return StringUtils.leftPad(Integer.toHexString(i), 8, '0'); }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String toHex(long l) { return StringUtils.leftPad(Long.toHexString(l), 16, '0'); }
From source file:at.beris.virtualfile.shell.Shell.java
private void list(boolean local) throws IOException { File file = local ? localFile : workingFile; if (file == null && !local) { System.out.println(NOT_CONNECTED_MSG); return;/* www .jav a 2s . c o m*/ } int maxLengthOwner = 0, maxLengthGroup = 0, maxLengthSize = 0; int maxLengthDateStr = 0, maxLengthTimeStr = 0; StringBuilder sb = new StringBuilder(); List<ExtFileModel> fileModelList = new ArrayList<>(); for (File childFile : file.list()) { ExtFileModel model = new ExtFileModel(); model.setUrl(childFile.getUrl()); model.setAttributes(childFile.getAttributes()); model.setDirectory(childFile.isDirectory()); model.setOwner(childFile.getOwner()); model.setGroup(childFile.getGroup()); model.setSize(childFile.getSize()); model.setLastModifiedTime(childFile.getLastModifiedTime()); UserPrincipal owner = model.getOwner(); if (owner != null && maxLengthOwner < owner.getName().length()) maxLengthOwner = model.getOwner().getName().length(); GroupPrincipal group = model.getGroup(); if (group != null && maxLengthGroup < group.getName().length()) maxLengthGroup = model.getGroup().getName().length(); String sizeString = String.valueOf(model.getSize()); if (maxLengthSize < sizeString.length()) maxLengthSize = sizeString.length(); if (model.getLastModifiedTime() != null) { Date lastModifiedDate = new Date(model.getLastModifiedTime().toMillis()); model.dateStr = DATE_FORMATTER.format(lastModifiedDate); if (maxLengthDateStr < model.dateStr.length()) maxLengthDateStr = model.dateStr.length(); model.timeStr = TIME_FORMATTER.format(lastModifiedDate); if (maxLengthTimeStr < model.timeStr.length()) maxLengthTimeStr = model.timeStr.length(); } else { model.dateStr = ""; model.timeStr = ""; } fileModelList.add(model); } for (ExtFileModel model : fileModelList) { sb.setLength(0); sb.append(model.isDirectory() ? 'd' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OWNER_READ) ? 'r' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OWNER_WRITE) ? 'w' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OWNER_EXECUTE) ? 'x' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.GROUP_READ) ? 'r' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.GROUP_WRITE) ? 'w' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.GROUP_EXECUTE) ? 'x' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OTHERS_READ) ? 'r' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OTHERS_WRITE) ? 'w' : '-'); sb.append(model.getAttributes().contains(PosixFilePermission.OTHERS_EXECUTE) ? 'x' : '-').append(' '); sb.append(StringUtils.rightPad(model.getOwner().getName(), maxLengthOwner, ' ')).append(' '); sb.append(StringUtils.rightPad(model.getGroup().getName(), maxLengthGroup, ' ')).append(' '); sb.append(StringUtils.leftPad(String.valueOf(model.getSize()), maxLengthSize, ' ')).append(' '); sb.append(StringUtils.leftPad(model.dateStr, maxLengthDateStr, ' ')).append(' '); sb.append(StringUtils.leftPad(model.timeStr, maxLengthTimeStr, ' ')).append(' '); sb.append(FileUtils.getName(model.getUrl().toString())); System.out.println(sb.toString()); } for (FileModel fileModel : fileModelList) fileModel.clear(); fileModelList.clear(); }
From source file:com.netsteadfast.greenstep.bsc.service.logic.impl.VisionLogicServiceImpl.java
@ServiceMethodAuthority(type = { ServiceMethodType.SELECT }) @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true) @Override/* w ww. j av a 2 s. c o m*/ public String findForMaxVisId(String date) throws ServiceException, Exception { if (super.isBlank(date) || !NumberUtils.isNumber(date) || date.length() != 8) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK)); } String maxVisionId = this.visionService.findForMaxVisId(BscConstants.HEAD_FOR_VIS_ID + date); if (StringUtils.isBlank(maxVisionId)) { return BscConstants.HEAD_FOR_VIS_ID + date + "001"; } int maxSeq = Integer.parseInt(maxVisionId.substring(11, 14)) + 1; if (maxSeq > 999) { throw new ServiceException( SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS) + " over max seq 999!"); } return BscConstants.HEAD_FOR_VIS_ID + date + StringUtils.leftPad(String.valueOf(maxSeq), 3, "0"); }
From source file:com.willwinder.ugs.nbp.setupwizard.panels.WizardPanelStepCalibration.java
@Override public void initialize() { getBackend().addUGSEventListener(this); getBackend().addControllerStateListener(this); WizardUtils.killAlarm(getBackend()); updateMeasurementEstimatesFields();// ww w. ja v a2 s.c om updateSettingFieldsFromFirmware(); if (updateTimer != null) { updateTimer.cancel(); } updateTimer = new Timer(); updateTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Position currentPosition = getBackend().getWorkPosition(); if (currentPosition != null) { labelPositionX.setText( StringUtils.leftPad(decimalFormat.format(currentPosition.get(Axis.X)) + " mm", 8, ' ')); labelPositionY.setText( StringUtils.leftPad(decimalFormat.format(currentPosition.get(Axis.Y)) + " mm", 8, ' ')); labelPositionZ.setText( StringUtils.leftPad(decimalFormat.format(currentPosition.get(Axis.Z)) + " mm", 8, ' ')); updateMeasurementEstimatesFields(); } WizardUtils.killAlarm(getBackend()); } }, 0, 200); }
From source file:com.hurence.logisland.processor.networkpacket.utils.PcapUtils.java
/** * Convert to hex./* w w w.j ava 2s . c o m*/ * * @param number * the number * @param length * the length * @return the string */ public static String convertToHex(int number, int length) { return StringUtils.leftPad(Integer.toHexString(number), length, '0'); }
From source file:com.francetelecom.clara.cloud.coremodel.ApplicationRepositoryTest.java
@Test @Transactional//from w ww. j a v a 2 s. co m public void application_with_valid_large_config_role_should_properly_persist() { // Given Application application = new Application("application label", "Application code"); ConfigRole configRole = new ConfigRole("myapp"); configRole.setLastModificationComment("Modified by Guillaume."); String long300CharsComment = StringUtils.leftPad("comment", 300, 'X'); configRole .setValues(Arrays.asList(new ConfigValue("myconfigset", "mykey", "myvalue", long300CharsComment))); application.addConfigRole(configRole); // When applicationRepository.save(application); Application retrievedApplication = applicationRepository.findOne(application.getId()); // Then List<ConfigRole> reloadedConfigRoles = retrievedApplication.listConfigRoles(); assertThat(reloadedConfigRoles.size()).isEqualTo(1); ConfigRole reloadedConfigRole = reloadedConfigRoles.get(0); List<ConfigValue> reloadedConfigValues = reloadedConfigRole.listValues(); assertThat(reloadedConfigValues.size()).isEqualTo(1); ConfigValue reloadedConfigValue = reloadedConfigValues.get(0); assertThat(reloadedConfigValue.getConfigSet()).isEqualTo("myconfigset"); assertThat(reloadedConfigValue.getKey()).isEqualTo("mykey"); assertThat(reloadedConfigValue.getValue()).isEqualTo("myvalue"); assertThat(reloadedConfigValue.getComment()).isEqualTo(long300CharsComment); }