List of usage examples for java.text MessageFormat format
public final String format(Object obj)
From source file:com.okta.tools.awscli.java
private static void UpdateCredentialsFile(String profileName, String awsAccessKey, String awsSecretKey, String awsSessionToken) throws IOException { ProfilesConfigFile profilesConfigFile = null; Object[] args = { new String(profileName) }; MessageFormat profileNameFormatWithBrackets = new MessageFormat("[{0}]"); String profileNameWithBrackets = profileNameFormatWithBrackets.format(args); try {//ww w . java 2 s . c o m profilesConfigFile = new ProfilesConfigFile(); } catch (AmazonClientException ace) { PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } try { if (profilesConfigFile != null && profilesConfigFile.getCredentials(profileName) != null) { //if we end up here, it means we were able to find a matching profile PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } } catch (AmazonClientException ace) { //this could happen if the default profile doesn't have a valid AWS Access Key ID //in this case, error would be "Unable to load credentials into profile [default]: AWS Access Key ID is not specified." PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); } catch (IllegalArgumentException iae) { //if we end up here, it means we were not able to find a matching profile so we need to append one PopulateCredentialsFile(profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); //FileWriter fileWriter = new FileWriter(System.getProperty("user.home") + "/.aws/credentials", true); //TODO: need to be updated to work with Windows //PrintWriter writer = new PrintWriter(fileWriter); //WriteNewProfile(writer, profileNameWithBrackets, awsAccessKey, awsSecretKey, awsSessionToken); //fileWriter.close(); } }
From source file:channellistmaker.channelfilemaker.ChannelDocumentMaker.java
private void addChannelElement(Document document, Element channels, Channel channel_o) { KeyFields kf = channel_o.getKeyfields(); Element channel = document.createElement(EPG_CHANNEL); channels.appendChild(channel);//from ww w . j av a2 s.co m this.addTextElement(document, channel, TRANSPORT_STREAM_ID, Integer.toString(kf.getTransportStreamId())); this.addTextElement(document, channel, ORIGINAL_NETWORK_ID, Integer.toString(kf.getOriginalNetworkId())); this.addTextElement(document, channel, SERVICE_ID, Integer.toString(kf.getServiceId())); this.addTextElement(document, channel, EPG_PHYSICAL_CHANNEL_NUMBER, Integer.toString(channel_o.getPhysicalChannelNumber())); this.addTextElement(document, channel, EPG_DISPLAY_NAME, channel_o.getDisplayName()); MessageFormat mf = new MessageFormat( "? = {0} ? = {1} = {2} ??? = {3} ??? = {4}"); Object[] message = { kf.getTransportStreamId(), kf.getOriginalNetworkId(), kf.getServiceId(), channel_o.getPhysicalChannelNumber(), channel_o.getDisplayName() }; LOG.info(mf.format(message)); }
From source file:com.xpn.xwiki.XWikiException.java
@Override public String getMessage() { StringBuilder buffer = new StringBuilder(); buffer.append("Error number "); buffer.append(getCode());/*from www . ja v a 2 s . co m*/ buffer.append(" in "); buffer.append(getModuleName()); String message = super.getMessage(); if (message != null) { buffer.append(": "); if (this.args == null) { buffer.append(message); } else { MessageFormat msgFormat = new MessageFormat(message); try { buffer.append(msgFormat.format(this.args)); } catch (Exception e) { buffer.append("Cannot format message [" + message + "] with args "); for (int i = 0; i < this.args.length; i++) { if (i != 0) { buffer.append(","); } buffer.append(this.args[i]); } } } } return buffer.toString(); }
From source file:libepg.epg.section.descriptor.Descriptor.java
/** * ??????????//from w ww. j av a 2 s . c o m * * @param descriptor ? */ public Descriptor(Descriptor descriptor) { this.descriptorTag = descriptor.descriptorTag; if (this.getClass() != this.descriptorTag.getDataType()) { MessageFormat msg1 = new MessageFormat( "??????????????={0} ?={1} ={2}"); Object[] parameters1 = { this.getClass(), this.descriptorTag.getDataType(), Hex.encodeHexString(descriptor.getData()) }; throw new IllegalArgumentException(msg1.format(parameters1)); } this.data = descriptor.data; }
From source file:net.jcreate.e3.table.message.AbstractMessageSource.java
/** * Resolve the given code and arguments as message in the given Locale, * returning null if not found. Does <i>not</i> fall back to the code * as default message. Invoked by getMessage methods. * @param code the code to lookup up, such as 'calculator.noRateSet' * @param args array of arguments that will be filled in for params * within the message/*from w w w . j a va2 s .c om*/ * @param locale the Locale in which to do the lookup * @return the resolved message, or <code>null</code> if not found * @see #getMessage(String, Object[], String, Locale) * @see #getMessage(String, Object[], Locale) * @see #getMessage(MessageSourceResolvable, Locale) * @see #setUseCodeAsDefaultMessage */ protected String getMessageInternal(String code, Object[] args, Locale locale) { if (code == null) { return null; } if (locale == null) { locale = Locale.getDefault(); } Object[] argsToUse = args; if (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args)) { // Optimized resolution: no arguments to apply, // therefore no MessageFormat needs to be involved. // Note that the default implementation still uses MessageFormat; // this can be overridden in specific subclasses. String message = resolveCodeWithoutArguments(code, locale); if (message != null) { return message; } } else { // Resolve arguments eagerly, for the case where the message // is defined in a parent MessageSource but resolvable arguments // are defined in the child MessageSource. argsToUse = resolveArguments(args, locale); MessageFormat messageFormat = resolveCode(code, locale); if (messageFormat != null) { synchronized (messageFormat) { return messageFormat.format(argsToUse); } } } // Not found -> check parent, if any. return getMessageFromParent(code, argsToUse, locale); }
From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitter.java
/** * 1:payload_unit_start_indicator?1?????0?????2??????????1?<br> * 2:payload_unit_start_indicator?1?????0????<br> * ?2???????????????<br>/* w ww .jav a 2 s . c o m*/ * ????+1??????????2?<br> * 3:payload_unit_start_indicator?0????????1? * * @return ??? <br> */ public synchronized Map<PAYLOAD_PART_KEY, byte[]> getSplittedPayLoad() { if (LOG.isTraceEnabled()) { LOG.trace(this.packet); } Map<PAYLOAD_PART_KEY, byte[]> temp = new HashMap<>(); EXEC: { if (this.packet .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.NOT_START_POINT) { LOG.trace("????"); temp.put(PAYLOAD_PART_KEY.ALL_PAYLOAD, this.packet.getPayload()); break EXEC; } if (this.packet .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.START_PES_OR_START_SECTION) { LOG.trace("???"); int pointerField = ByteConverter.byteToInt(this.packet.getPayload()[0]); int tempLength = this.packet.getPayload().length - 1; byte[] tempArray = new byte[tempLength]; System.arraycopy(this.packet.getPayload(), 1, tempArray, 0, tempArray.length); if (LOG.isTraceEnabled()) { MessageFormat msg1 = new MessageFormat( "?={0} ={1} 2??={2}"); Object[] parameters1 = { pointerField, Hex.encodeHexString(this.packet.getPayload()), Hex.encodeHexString(tempArray) }; LOG.trace(msg1.format(parameters1)); } if (pointerField == 0) { temp.put(PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE, tempArray); break EXEC; } else { byte[] prev = new byte[pointerField]; System.arraycopy(tempArray, 0, prev, 0, prev.length); temp.put(PAYLOAD_PART_KEY.PREV_POINTER, prev); byte[] next = new byte[tempArray.length - pointerField]; System.arraycopy(tempArray, pointerField, next, 0, next.length); temp.put(PAYLOAD_PART_KEY.NEXT_POINTER, next); break EXEC; } } } dumpMap(temp); return Collections.unmodifiableMap(temp); }
From source file:cherry.foundation.numbering.NumberingManagerImpl.java
@Transactional @Override/*from w ww .j a v a 2 s. c om*/ public String issueAsString(String numberName) { checkArgument(numberName != null, "numberName must not be null"); NumberingDefinition def = getNumberingDefinition(numberName); MessageFormat fmt = new MessageFormat(def.getTemplate()); long current = numberingStore.loadAndLock(numberName); int offset = 0; try { long v = current + 1; checkState(v >= def.getMinValue(), "%s must be >= %s", numberName, def.getMinValue()); checkState(v <= def.getMaxValue(), "%s must be <= %s", numberName, def.getMaxValue()); String result = fmt.format(new Object[] { Long.valueOf(v) }); offset = 1; return result; } finally { numberingStore.saveAndUnlock(numberName, current + offset); } }
From source file:libepg.epg.section.Section.java
/** * ??????ID????+3?????????????// w ww . j a va 2 s . c o m * * @param data ? * @throws IllegalArgumentException * 1:???????ID????3???????<br> * 2:?2?0?????<br> * 3:???????preferedTableID???????????<br> */ public Section(byte[] data) throws IllegalArgumentException { byte[] temp = Arrays.copyOf(data, data.length); final int id = ByteConverter.byteToInt(temp[0]); tableId = TABLE_ID.reverseLookUp(id); String hexValue = Hex.encodeHexString(data); //ID??ID????????????ID?????????????(?????ID???????????) if (tableId == null) { MessageFormat msg2 = new MessageFormat( "????? ???={0}"); Object[] parameters2 = { hexValue }; LOG.trace(msg2.format(parameters2)); throw new IllegalArgumentException(msg2.format(parameters2)); } byte[] t = new byte[2]; System.arraycopy(temp, 1, t, 0, t.length); int sectionLength = ByteConverter.bytesToInt(t); if (LOG.isTraceEnabled()) { LOG.trace("b1 = " + Integer.toHexString(sectionLength)); } sectionLength = sectionLength & 0x0FFF; if (LOG.isTraceEnabled()) { LOG.trace("b2 = " + Integer.toHexString(sectionLength)); } //??????? if (sectionLength > tableId.getMaxSectionLength().getMaxSectionBodyLength()) { MessageFormat msg3 = new MessageFormat( "?????????={0} ?={1} ???={2}"); Object[] parameters3 = { tableId.getMaxSectionLength().getMaxSectionBodyLength(), sectionLength, hexValue }; LOG.trace(msg3.format(parameters3)); throw new IllegalArgumentException(msg3.format(parameters3)); } //??????????? int targetLength = sectionLength + 3; byte[] sectionByteArray = new byte[targetLength]; System.arraycopy(temp, 0, sectionByteArray, 0, sectionByteArray.length); if (LOG.isTraceEnabled()) { MessageFormat msg1 = new MessageFormat("\n??={0}\n?={1}"); Object[] parameters1 = { Hex.encodeHexString(temp), Hex.encodeHexString(sectionByteArray) }; LOG.trace(msg1.format(parameters1)); } this.data = new ByteDataBlock(sectionByteArray); }
From source file:libepg.epg.section.sectionreconstructor.SectionReconstructor.java
/** * @param parcels ????// www . j a v a 2 s . c om * @param pid ?pid * @throws IllegalArgumentException ??pid?pid????????? */ public SectionReconstructor(List<TsPacketParcel> parcels, int pid) throws IllegalArgumentException { this.pid = pid; List<TsPacketParcel> tempParcels = new ArrayList<>(); tempParcels.addAll(parcels); for (TsPacketParcel parcel : tempParcels) { if (this.pid == parcel.getPacket().getPid()) { } else { MessageFormat WRONG_PID = new MessageFormat( "??Pid?Pid???????????Pid={0} ={1}"); Object[] parameters = { Integer.toHexString(this.getPid()), parcel.getPacket().toString() }; throw new IllegalArgumentException(WRONG_PID.format(parameters)); } } this.parcels = Collections.unmodifiableList(tempParcels); }
From source file:ca.simplegames.micro.extensions.i18n.AbstractMessageSource.java
/** * Resolve the given code and arguments as message in the given Locale, * returning null if not found. Does <i>not</i> fall back to the code * as default message. Invoked by getMessage methods. * * @param code the code to lookup up, such as 'calculator.noRateSet' * @param args array of arguments that will be filled in for params * within the message//from w ww . j a v a 2 s .c o m * @param locale the Locale in which to do the lookup * @return the resolved message, or <code>null</code> if not found * @see #getMessage(String, Object[], String, Locale) * @see #getMessage(String, Object[], Locale) * @see #getMessage(MessageSourceResolvable, Locale) * @see #setUseCodeAsDefaultMessage */ protected String getMessageInternal(String code, Object[] args, Locale locale) { if (code == null) { return null; } if (locale == null) { locale = Locale.getDefault(); } Object[] argsToUse = args; if (!isAlwaysUseMessageFormat() && (args == null || args.length == 0)) { // Optimized resolution: no arguments to apply, // therefore no MessageFormat needs to be involved. // Note that the default implementation still uses MessageFormat; // this can be overridden in specific subclasses. String message = resolveCodeWithoutArguments(code, locale); if (message != null) { return message; } } else { // Resolve arguments eagerly, for the case where the message // is defined in a parent MessageSource but resolvable arguments // are defined in the child MessageSource. argsToUse = resolveArguments(args, locale); MessageFormat messageFormat = resolveCode(code, locale); if (messageFormat != null) { synchronized (messageFormat) { return messageFormat.format(argsToUse); } } } // Not found -> check parent, if any. return getMessageFromParent(code, argsToUse, locale); }