本文整理匯總了Java中java.util.IllegalFormatException類的典型用法代碼示例。如果您正苦於以下問題:Java IllegalFormatException類的具體用法?Java IllegalFormatException怎麽用?Java IllegalFormatException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IllegalFormatException類屬於java.util包,在下文中一共展示了IllegalFormatException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: evaluate
import java.util.IllegalFormatException; //導入依賴的package包/類
@Override
public IpAddress evaluate(FunctionArgs args, EvaluationContext context) {
final String ipString = String.valueOf(ipParam.required(args, context));
try {
final InetAddress inetAddress = InetAddresses.forString(ipString);
return new IpAddress(inetAddress);
} catch (IllegalArgumentException e) {
final Optional<String> defaultValue = defaultParam.optional(args, context);
if (!defaultValue.isPresent()) {
return new IpAddress(ANYV4);
}
try {
return new IpAddress(InetAddresses.forString(defaultValue.get()));
} catch (IllegalFormatException e1) {
log.warn("Parameter `default` for to_ip() is not a valid IP address: {}", defaultValue.get());
throw e1;
}
}
}
示例2: LabelPattern
import java.util.IllegalFormatException; //導入依賴的package包/類
/**
* Constructs a new pattern, with a given format string
* and list of attribute field names.
*/
public LabelPattern(String format, List<String> argNames) throws FormatException {
this.format = format;
this.argNames.addAll(argNames);
List<Object> testValues1 = new ArrayList<>();
List<Object> testValues2 = new ArrayList<>();
for (int i = 0; i < argNames.size(); i++) {
this.argPositions.put(argNames.get(i), i);
testValues1.add(null);
testValues2.add("");
}
try {
getLabel(testValues1.toArray());
getLabel(testValues2.toArray());
} catch (IllegalFormatException exc) {
throw new FormatException("Format string \"%s\" not valid for %d arguments", format,
argNames.size());
}
}
示例3: getOutputString
import java.util.IllegalFormatException; //導入依賴的package包/類
/**
* Returns the instantiated output string for a given transition, if any.
* @return the instantiated output string, or {@code null} if there is none
* @throws FormatException if the format string of the rule
* does not correspond to the actual rule parameters.
*/
public static String getOutputString(GraphTransition trans) throws FormatException {
String result = null;
String formatString = trans.getAction()
.getFormatString();
if (formatString != null && !formatString.isEmpty()) {
List<Object> args = new ArrayList<>();
for (HostNode arg : trans.label()
.getArguments()) {
if (arg instanceof ValueNode) {
args.add(((ValueNode) arg).getValue());
} else {
args.add(arg.toString());
}
}
try {
result = String.format(formatString, args.toArray());
} catch (IllegalFormatException e) {
throw new FormatException("Error in rule output string: %s", e.getMessage());
}
}
return result;
}
示例4: getString
import java.util.IllegalFormatException; //導入依賴的package包/類
public static String getString(String id, Object... args) {
synchronized (lock) {
if (mStrings.containsKey(id)) {
try {
return String.format(mStrings.get(id).toString(), args);
} catch (IllegalFormatException e) {
Log.e(TAG, "A string was found with wrong format parameters! The string is: " + id);
return mStrings.get(id).toString();
}
} else {
Crashlytics.logException(new RuntimeException("String not found: " + id));
return "";
}
}
}
示例5: testGet
import java.util.IllegalFormatException; //導入依賴的package包/類
@Test
public void testGet() throws Exception {
assertThat(map.get(new BadRequestException()), is(equalTo(HttpStatus.BAD_REQUEST)));
assertThat(map.get(BadRequestException.class), is(equalTo(HttpStatus.BAD_REQUEST)));
assertThat(map.get(ConflictException.class), is(equalTo(HttpStatus.CONFLICT)));
assertThat(map.get(NotFoundException.class), is(equalTo(HttpStatus.NOT_FOUND)));
assertThat(map.get(NotModifiedException.class), is(equalTo(HttpStatus.NOT_MODIFIED)));
assertThat(map.get(UnauthorizedException.class), is(equalTo(HttpStatus.UNAUTHORIZED)));
assertThat(map.get(Exception.class), is(equalTo(HttpStatus.INTERNAL_SERVER_ERROR)));
assertThat(map.get(IllegalArgumentException.class), is(equalTo(HttpStatus.INTERNAL_SERVER_ERROR)));
map.put(IllegalArgumentException.class, HttpStatus.ACCEPTED);
assertThat(map.get(IllegalFormatException.class), is(either(equalTo(HttpStatus.INTERNAL_SERVER_ERROR)).or(equalTo(HttpStatus.ACCEPTED))));
}
示例6: updateDisplay
import java.util.IllegalFormatException; //導入依賴的package包/類
private void updateDisplay(int value) {
if (!TextUtils.isEmpty(mFormat)) {
mValue.setVisibility(View.VISIBLE);
value = (value + mSteppedMinValue) * mStepValue;
String text;
try {
if (mUseDisplayDividerValue) {
float floatValue = (float) value / mDisplayDividerValue;
text = String.format(mFormat, floatValue);
} else {
text = String.format(mFormat, value);
}
} catch (IllegalFormatException e) {
text = Integer.toString(value);
}
mValue.setText(text);
} else {
mValue.setVisibility(View.GONE);
}
}
示例7: log
import java.util.IllegalFormatException; //導入依賴的package包/類
/**
* Logs a formatted string to the console using the source object's name as
* the log tag. If the source object is null, the default tag (see
* {@link LogUtils#TAG} is used.
* <p>
* Example usage: <br>
* <code>
* LogUtils.log(this, Log.ERROR, "Invalid value: %d", value);
* </code>
*
* @param source The object that generated the log event.
* @param priority The log entry priority, see
* {@link Log#println(int, String, String)}.
* @param format A format string, see
* {@link String#format(String, Object...)}.
* @param args String formatter arguments.
*/
public static void log(Object source, int priority, String format, Object... args) {
if (priority < LOG_LEVEL) {
return;
}
final String sourceClass;
if (source == null) {
sourceClass = TAG;
} else if (source instanceof Class<?>) {
sourceClass = ((Class<?>) source).getSimpleName();
} else {
sourceClass = source.getClass().getSimpleName();
}
try {
Log.println(priority, sourceClass, String.format(format, args));
} catch (IllegalFormatException e) {
Log.e(TAG, "Bad formatting string: \"" + format + "\"", e);
}
}
示例8: resolve
import java.util.IllegalFormatException; //導入依賴的package包/類
public static final String resolve( String key, Object[] parameters ) {
// assertion
if (key == null) {
return "";
}
ResourceBundle bundle;
String formatString;
try {
bundle = ResourceBundle.getBundle("TopologyBundle", Locale.getDefault(), ProjectBundleResolver.class.getClassLoader());
// resolving key
String s = bundle.getString(key);
formatString = String.format(s, parameters);
return formatString;
}
catch (MissingResourceException ex) {
return key;
}
catch (IllegalFormatException ife){
return key;
}
}
示例9: resolve
import java.util.IllegalFormatException; //導入依賴的package包/類
private final String resolve( String key, Locale locale ) {
if (key == null) {
return "";
}
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle("de.linogistix.los.inventory.res.Bundle", locale, InventoryBundleResolver.class.getClassLoader());
String s = bundle.getString(key);
return s;
}
catch (MissingResourceException ex) {
log.error("Exception: "+ex.getMessage());
return key;
}
catch (IllegalFormatException ife){
log.error("Exception: "+ife.getMessage());
return key;
}
}
示例10: resolve
import java.util.IllegalFormatException; //導入依賴的package包/類
private final String resolve( String key, Locale locale ) {
if (key == null) {
return "";
}
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle("de.linogistix.los.location.res.Bundle", locale, BundleResolver.class.getClassLoader());
String s = bundle.getString(key);
return s;
}
catch (MissingResourceException ex) {
log.error("Exception: "+ex.getMessage());
return key;
}
catch (IllegalFormatException ife){
log.error("Exception: "+ife.getMessage());
return key;
}
}
示例11: resolve
import java.util.IllegalFormatException; //導入依賴的package包/類
private final String resolve( String key, Locale locale ) {
if (key == null) {
return "";
}
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle("de.linogistix.los.res.Bundle", locale, BundleResolver.class.getClassLoader());
String s = bundle.getString(key);
return s;
}
catch (MissingResourceException ex) {
log.error("Exception: "+ex.getMessage());
return key;
}
catch (IllegalFormatException ife){
log.error("Exception: "+ife.getMessage());
return key;
}
}
示例12: getTableNameFormat
import java.util.IllegalFormatException; //導入依賴的package包/類
private String getTableNameFormat(Config config, PersistenceConfig defaultValues) {
String formatStr = config.tableNameFormat;
if ( null == formatStr && null != defaultValues ) {
formatStr = defaultValues.getTableNameFormat();
}
if ( null == formatStr ) return null;
try {
String.format(formatStr, "");
} catch ( IllegalFormatException ex ) {
throw new IllegalArgumentException(
"Expected 'tableNameFormat' in "+_file+
" to be format string containing a single %s: "+
ex.getMessage());
}
return formatStr;
}
示例13: formatValue
import java.util.IllegalFormatException; //導入依賴的package包/類
/**
* Attempt to format the tag value; if the actual tag value is missing or
* the tag value could not be formatted for whatever reason, then the
* <code>toString</code> of the argument array is appended to the tag
* value...
*/
private static String formatValue(Locale locale, String tagValue, String tag, Object... arguments) {
String formattedTagValue;
if (tagValue != tag) // The identity equality is fine; that's what I want!
{
try {
// The locale is required for example to convert a double into
// its string representation
// when processing %s (of a double value) or even a %d I guess
// (e.g., using '.' or ',' )
formattedTagValue = String.format(locale, tagValue, arguments);
} catch (IllegalFormatException ex) {
Log.warn("Illegal format for tag [" + tag + "] - " + ex.getMessage(), ex);
formattedTagValue = tagValue + " " + Arrays.toString(arguments);
// what else can I do here?
}
} else {
formattedTagValue = tagValue + " " + Arrays.toString(arguments);
// what else can I do here?
}
return formattedTagValue;
}
示例14: modifySSHKeyName
import java.util.IllegalFormatException; //導入依賴的package包/類
public static String modifySSHKeyName(String name) {
String[] nameRaw = name.split("_");
String indexStr = nameRaw[nameRaw.length - 1];
Integer index = 2;
if (StringUtils.isNumeric(indexStr)) {
try {
index = Integer.parseInt(indexStr) + 1;
nameRaw = Arrays.copyOf(nameRaw, nameRaw.length - 1);
} catch (IllegalFormatException e) {
//nop
}
}
return StringUtils.join(nameRaw) + "_" + index;
}
示例15: condenseFileSize
import java.util.IllegalFormatException; //導入依賴的package包/類
/**
* Condense a file size in bytes to it's highest form (i.e. KB, MB, GB, etc)
*
* @param bytes the size in bytes
* @param precision the precision constant {@code ONE_DIGIT}, {@code TWO_DIGIT}, {@code THREE_DIGIT}
* @return the condensed string
*/
public static String condenseFileSize(long bytes, String precision) throws IllegalFormatException {
// Kilobyte Check
float kilo = bytes / 1024f;
float mega = kilo / 1024f;
float giga = mega / 1024f;
float tera = giga / 1024f;
float peta = tera / 1024f;
// Determine which value to send back
if(peta > 1)
return String.format(precision + " PB", peta);
else if (tera > 1)
return String.format(precision + " TB", tera);
else if(giga > 1)
return String.format(precision + " GB", giga);
else if(mega > 1)
return String.format(precision + " MB", mega);
else if(kilo > 1)
return String.format(precision + " KB", kilo);
else
return bytes + " b";
}