diff options
33 files changed, 169 insertions, 1048 deletions
diff --git a/logging/src/main/java/java/util/logging/ErrorManager.java b/logging/src/main/java/java/util/logging/ErrorManager.java index 708ddfa..6570fa7 100644 --- a/logging/src/main/java/java/util/logging/ErrorManager.java +++ b/logging/src/main/java/java/util/logging/ErrorManager.java @@ -17,8 +17,6 @@ package java.util.logging; -import org.apache.harmony.logging.internal.nls.Messages; - /** * An error reporting facility for {@link Handler} implementations to record any * error that may happen during logging. {@code Handlers} should report errors @@ -98,15 +96,12 @@ public class ErrorManager { } called = true; } - System.err.println(this.getClass().getName() - + ": " + FAILURES[errorCode]); //$NON-NLS-1$ + System.err.println(this.getClass().getName() + ": " + FAILURES[errorCode]); if (message != null) { - // logging.1E=Error message - {0} - System.err.println(Messages.getString("logging.1E", message)); //$NON-NLS-1$ + System.err.println("Error message - " + message); } if (exception != null) { - // logging.1F=Exception - {0} - System.err.println(Messages.getString("logging.1F", exception)); //$NON-NLS-1$ + System.err.println("Exception - " + exception); } } } diff --git a/logging/src/main/java/java/util/logging/FileHandler.java b/logging/src/main/java/java/util/logging/FileHandler.java index bd02ef1..3d61d7d 100644 --- a/logging/src/main/java/java/util/logging/FileHandler.java +++ b/logging/src/main/java/java/util/logging/FileHandler.java @@ -29,8 +29,6 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Hashtable; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A {@code FileHandler} writes logging records into a specified file or a * rotating set of files. @@ -228,9 +226,8 @@ public class FileHandler extends StreamHandler { String className = this.getClass().getName(); pattern = (null == p) ? getStringProperty(className + ".pattern", DEFAULT_PATTERN) : p; - if (null == pattern || "".equals(pattern)) { - // logging.19=Pattern cannot be empty - throw new NullPointerException(Messages.getString("logging.19")); + if (pattern == null || pattern.isEmpty()) { + throw new NullPointerException("Pattern cannot be empty or null"); } append = (null == a) ? getBooleanProperty(className + ".append", DEFAULT_APPEND) : a.booleanValue(); @@ -255,9 +252,7 @@ public class FileHandler extends StreamHandler { output = new MeasureOutputStream(new BufferedOutputStream( new FileOutputStream(files[0]))); } catch (FileNotFoundException e1) { - // logging.1A=Error happened when open log file. - this.getErrorManager().error(Messages.getString("logging.1A"), //$NON-NLS-1$ - e1, ErrorManager.OPEN_FAILURE); + this.getErrorManager().error("Error opening log file", e1, ErrorManager.OPEN_FAILURE); } setOutputStream(output); } @@ -401,12 +396,10 @@ public class FileHandler extends StreamHandler { * if the pattern is {@code null}. */ public FileHandler(String pattern) throws IOException { - if (pattern.equals("")) { //$NON-NLS-1$ - // logging.19=Pattern cannot be empty - throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$ + if (pattern.isEmpty()) { + throw new IllegalArgumentException("Pattern cannot be empty"); } - init(pattern, null, Integer.valueOf(DEFAULT_LIMIT), Integer - .valueOf(DEFAULT_COUNT)); + init(pattern, null, Integer.valueOf(DEFAULT_LIMIT), Integer.valueOf(DEFAULT_COUNT)); } /** @@ -435,10 +428,9 @@ public class FileHandler extends StreamHandler { * if {@code pattern} is {@code null}. */ public FileHandler(String pattern, boolean append) throws IOException { - if (pattern.equals("")) { //$NON-NLS-1$ - throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$ + if (pattern.isEmpty()) { + throw new IllegalArgumentException("Pattern cannot be empty"); } - init(pattern, Boolean.valueOf(append), Integer.valueOf(DEFAULT_LIMIT), Integer.valueOf(DEFAULT_COUNT)); } @@ -473,13 +465,11 @@ public class FileHandler extends StreamHandler { * if {@code pattern} is {@code null}. */ public FileHandler(String pattern, int limit, int count) throws IOException { - if (pattern.equals("")) { //$NON-NLS-1$ - throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$ + if (pattern.isEmpty()) { + throw new IllegalArgumentException("Pattern cannot be empty"); } if (limit < 0 || count < 1) { - // logging.1B=The limit and count property must be larger than 0 and - // 1, respectively - throw new IllegalArgumentException(Messages.getString("logging.1B")); //$NON-NLS-1$ + throw new IllegalArgumentException("limit < 0 || count < 1"); } init(pattern, null, Integer.valueOf(limit), Integer.valueOf(count)); } @@ -516,18 +506,14 @@ public class FileHandler extends StreamHandler { * @throws NullPointerException * if {@code pattern} is {@code null}. */ - public FileHandler(String pattern, int limit, int count, boolean append) - throws IOException { - if (pattern.equals("")) { //$NON-NLS-1$ - throw new IllegalArgumentException(Messages.getString("logging.19")); //$NON-NLS-1$ + public FileHandler(String pattern, int limit, int count, boolean append) throws IOException { + if (pattern.isEmpty()) { + throw new IllegalArgumentException("Pattern cannot be empty"); } if (limit < 0 || count < 1) { - // logging.1B=The limit and count property must be larger than 0 and - // 1, respectively - throw new IllegalArgumentException(Messages.getString("logging.1B")); //$NON-NLS-1$ + throw new IllegalArgumentException("limit < 0 || count < 1"); } - init(pattern, Boolean.valueOf(append), Integer.valueOf(limit), Integer - .valueOf(count)); + init(pattern, Boolean.valueOf(append), Integer.valueOf(limit), Integer.valueOf(count)); } /** diff --git a/logging/src/main/java/java/util/logging/Handler.java b/logging/src/main/java/java/util/logging/Handler.java index a5b92a0..d1aaef2 100644 --- a/logging/src/main/java/java/util/logging/Handler.java +++ b/logging/src/main/java/java/util/logging/Handler.java @@ -22,8 +22,6 @@ import java.nio.charset.Charset; import java.security.AccessController; import java.security.PrivilegedExceptionAction; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A {@code Handler} object accepts a logging request and exports the desired * messages to a target, for example, a file, the console, etc. It can be @@ -98,11 +96,7 @@ public abstract class Handler { // print error message in some format void printInvalidPropMessage(String key, String value, Exception e) { - // logging.12=Invalid property value for - String msg = new StringBuilder().append( - Messages.getString("logging.12")) //$NON-NLS-1$ - .append(prefix).append(":").append(key).append("/").append( //$NON-NLS-1$//$NON-NLS-2$ - value).toString(); + String msg = "Invalid property value for " + prefix + ":" + key + "/" + value; errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE); } @@ -286,21 +280,16 @@ public abstract class Handler { * @throws UnsupportedEncodingException * if the specified encoding is not supported by the runtime. */ - void internalSetEncoding(String newEncoding) - throws UnsupportedEncodingException { + void internalSetEncoding(String newEncoding) throws UnsupportedEncodingException { // accepts "null" because it indicates using default encoding - if (null == newEncoding) { + if (newEncoding == null) { this.encoding = null; } else { if (Charset.isSupported(newEncoding)) { this.encoding = newEncoding; } else { - // logging.13=The encoding "{0}" is not supported. - throw new UnsupportedEncodingException(Messages.getString( - "logging.13", //$NON-NLS-1$ - newEncoding)); + throw new UnsupportedEncodingException(newEncoding); } - } } diff --git a/logging/src/main/java/java/util/logging/Level.java b/logging/src/main/java/java/util/logging/Level.java index f988127..2c7ac53 100644 --- a/logging/src/main/java/java/util/logging/Level.java +++ b/logging/src/main/java/java/util/logging/Level.java @@ -17,6 +17,7 @@ package java.util.logging; +import dalvik.system.VMStack; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; @@ -26,11 +27,6 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; -import org.apache.harmony.logging.internal.nls.Messages; -// BEGIN android-changed -import dalvik.system.VMStack; -// END android-changed - /** * {@code Level} objects are used to indicate the level of logging. There are a * set of predefined logging levels, each associated with an integer value. @@ -107,8 +103,7 @@ public class Level implements Serializable { */ public static Level parse(String name) throws IllegalArgumentException { if (name == null) { - // logging.1C=The 'name' parameter is null. - throw new NullPointerException(Messages.getString("logging.1C")); //$NON-NLS-1$ + throw new NullPointerException("name == null"); } boolean isNameAnInt; @@ -142,9 +137,7 @@ public class Level implements Serializable { } if (!isNameAnInt) { - // logging.1D=Cannot parse this name: {0} - throw new IllegalArgumentException(Messages.getString( - "logging.1D", name)); //$NON-NLS-1$ + throw new IllegalArgumentException("Cannot parse name '" + name + "'"); } return new Level(name, nameAsInt); @@ -207,8 +200,7 @@ public class Level implements Serializable { */ protected Level(String name, int level, String resourceBundleName) { if (name == null) { - // logging.1C=The 'name' parameter is null. - throw new NullPointerException(Messages.getString("logging.1C")); //$NON-NLS-1$ + throw new NullPointerException("name == null"); } this.name = name; this.value = level; diff --git a/logging/src/main/java/java/util/logging/LogManager.java b/logging/src/main/java/java/util/logging/LogManager.java index 0e76b68..c07f6bf 100644 --- a/logging/src/main/java/java/util/logging/LogManager.java +++ b/logging/src/main/java/java/util/logging/LogManager.java @@ -23,8 +23,6 @@ package java.util.logging; // javax.management support (MBeans) has been dropped. // END android-note -import org.apache.harmony.logging.internal.nls.Messages; - import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.BufferedInputStream; @@ -126,11 +124,10 @@ import java.util.StringTokenizer; public class LogManager { /** The line separator of the underlying OS. */ - private static final String lineSeparator = getPrivilegedSystemProperty("line.separator"); //$NON-NLS-1$ + private static final String lineSeparator = getPrivilegedSystemProperty("line.separator"); /** The shared logging permission. */ - private static final LoggingPermission perm = new LoggingPermission( - "control", null); //$NON-NLS-1$ + private static final LoggingPermission perm = new LoggingPermission("control", null); /** The singleton instance. */ static LogManager manager; @@ -138,7 +135,7 @@ public class LogManager { /** * The {@code String} value of the {@link LoggingMXBean}'s ObjectName. */ - public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; //$NON-NLS-1$ + public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; /** * Get the {@code LoggingMXBean} instance. this implementation always throws @@ -147,39 +144,7 @@ public class LogManager { * @return the {@code LoggingMXBean} instance */ public static LoggingMXBean getLoggingMXBean() { - // BEGIN android-added - throw new UnsupportedOperationException(); - // END android-added - // BEGIN android-removed - // try { - // ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME); - // MBeanServer platformBeanServer = ManagementFactory - // .getPlatformMBeanServer(); - // Set<?> loggingMXBeanSet = platformBeanServer.queryMBeans( - // loggingMXBeanName, null); - // - // if (loggingMXBeanSet.size() != 1) { - // // logging.21=There Can Be Only One logging MX bean. - // throw new AssertionError(Messages.getString("logging.21")); //$NON-NLS-1$ - // } - // - // Iterator<?> i = loggingMXBeanSet.iterator(); - // ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next(); - // String lmxbcn = loggingMXBeanOI.getClassName(); - // Class<?> lmxbc = Class.forName(lmxbcn); - // Method giMethod = lmxbc.getDeclaredMethod("getInstance"); //$NON-NLS-1$ - // giMethod.setAccessible(true); - // LoggingMXBean lmxb = (LoggingMXBean) giMethod.invoke(null, - // new Object[] {}); - // - // return lmxb; - // } catch (Exception e) { - // // TODO - // // e.printStackTrace(); - // } - // // logging.22=Exception occurred while getting the logging MX bean. - // throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$ - // END android-removed + throw new UnsupportedOperationException(); } // FIXME: use weak reference to avoid heap memory leak @@ -195,8 +160,7 @@ public class LogManager { // init LogManager singleton instance AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { - String className = System - .getProperty("java.util.logging.manager"); //$NON-NLS-1$ + String className = System.getProperty("java.util.logging.manager"); if (null != className) { manager = (LogManager) getInstanceByClass(className); @@ -213,7 +177,7 @@ public class LogManager { } // if global logger has been initialized, set root as its parent - Logger root = new Logger("", null); //$NON-NLS-1$ + Logger root = new Logger("", null); root.setLevel(Level.INFO); Logger.global.setParent(root); @@ -313,14 +277,14 @@ public class LogManager { if (parent != null) { setParent(logger, parent); break; - } else if (getProperty(parentName + ".level") != null || //$NON-NLS-1$ - getProperty(parentName + ".handlers") != null) { //$NON-NLS-1$ + } else if (getProperty(parentName + ".level") != null || + getProperty(parentName + ".handlers") != null) { parent = Logger.getLogger(parentName); setParent(logger, parent); break; } } - if (parent == null && null != (parent = loggers.get(""))) { //$NON-NLS-1$ + if (parent == null && null != (parent = loggers.get(""))) { setParent(logger, parent); } @@ -403,20 +367,16 @@ public class LogManager { */ public void readConfiguration() throws IOException { // check config class - String configClassName = System - .getProperty("java.util.logging.config.class"); //$NON-NLS-1$ + String configClassName = System.getProperty("java.util.logging.config.class"); if (null == configClassName || null == getInstanceByClass(configClassName)) { // if config class failed, check config file - String configFile = System - .getProperty("java.util.logging.config.file"); //$NON-NLS-1$ + String configFile = System.getProperty("java.util.logging.config.file"); if (null == configFile) { // if cannot find configFile, use default logging.properties - configFile = new StringBuilder().append( - System.getProperty("java.home")).append(File.separator) //$NON-NLS-1$ - .append("lib").append(File.separator).append( //$NON-NLS-1$ - "logging.properties").toString(); //$NON-NLS-1$ + configFile = System.getProperty("java.home") + File.separator + "lib" + + File.separator + "logging.properties"; } InputStream input = null; @@ -458,17 +418,14 @@ public class LogManager { // use SystemClassLoader to load class from system classpath static Object getInstanceByClass(final String className) { try { - Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass( - className); + Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(className); return clazz.newInstance(); } catch (Exception e) { try { - Class<?> clazz = Thread.currentThread().getContextClassLoader() - .loadClass(className); + Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); return clazz.newInstance(); } catch (Exception innerE) { - // logging.20=Loading class "{0}" failed - System.err.println(Messages.getString("logging.20", className)); //$NON-NLS-1$ + System.err.println("Loading class '" + className + "' failed"); System.err.println(innerE); return null; } @@ -490,9 +447,9 @@ public class LogManager { } // parse property "config" and apply setting - String configs = props.getProperty("config"); //$NON-NLS-1$ + String configs = props.getProperty("config"); if (null != configs) { - StringTokenizer st = new StringTokenizer(configs, " "); //$NON-NLS-1$ + StringTokenizer st = new StringTokenizer(configs, " "); while (st.hasMoreTokens()) { String configerName = st.nextToken(); getInstanceByClass(configerName); @@ -502,7 +459,7 @@ public class LogManager { // set levels for logger Collection<Logger> allLoggers = loggers.values(); for (Logger logger : allLoggers) { - String property = props.getProperty(logger.getName() + ".level"); //$NON-NLS-1$ + String property = props.getProperty(logger.getName() + ".level"); if (null != property) { logger.setLevel(Level.parse(property)); } @@ -553,7 +510,7 @@ public class LogManager { logger.reset(); } } - Logger root = loggers.get(""); //$NON-NLS-1$ + Logger root = loggers.get(""); if (null != root) { root.setLevel(Level.INFO); } diff --git a/logging/src/main/java/java/util/logging/LogRecord.java b/logging/src/main/java/java/util/logging/LogRecord.java index f810e12..d4466bf 100644 --- a/logging/src/main/java/java/util/logging/LogRecord.java +++ b/logging/src/main/java/java/util/logging/LogRecord.java @@ -24,8 +24,6 @@ import java.io.Serializable; import java.util.MissingResourceException; import java.util.ResourceBundle; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A {@code LogRecord} object represents a logging request. It is passed between * the logging framework and individual logging handlers. Client applications @@ -154,9 +152,8 @@ public class LogRecord implements Serializable { * if {@code level} is {@code null}. */ public LogRecord(Level level, String msg) { - if (null == level) { - // logging.4=The 'level' parameter is null. - throw new NullPointerException(Messages.getString("logging.4")); //$NON-NLS-1$ + if (level == null) { + throw new NullPointerException("level == null"); } this.level = level; this.message = msg; @@ -200,9 +197,8 @@ public class LogRecord implements Serializable { * if {@code level} is {@code null}. */ public void setLevel(Level level) { - if (null == level) { - // logging.4=The 'level' parameter is null. - throw new NullPointerException(Messages.getString("logging.4")); //$NON-NLS-1$ + if (level == null) { + throw new NullPointerException("level == null"); } this.level = level; } @@ -489,9 +485,7 @@ public class LogRecord implements Serializable { byte minor = in.readByte(); // only check MAJOR version if (major != MAJOR) { - // logging.5=Different version - {0}.{1} - throw new IOException(Messages.getString("logging.5", //$NON-NLS-1$ - Byte.valueOf(major), Byte.valueOf(minor))); + throw new IOException("Different version " + Byte.valueOf(major) + "." + Byte.valueOf(minor)); } int length = in.readInt(); diff --git a/logging/src/main/java/java/util/logging/Logger.java b/logging/src/main/java/java/util/logging/Logger.java index e03ca9f..8271022 100644 --- a/logging/src/main/java/java/util/logging/Logger.java +++ b/logging/src/main/java/java/util/logging/Logger.java @@ -26,8 +26,6 @@ package java.util.logging; import dalvik.system.DalvikLogHandler; import dalvik.system.DalvikLogging; -import org.apache.harmony.logging.internal.nls.Messages; - import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; @@ -340,9 +338,8 @@ public class Logger { // Failed to load using the current class's classloader, ignore } } - // logging.8=Failed to load the specified resource bundle "{0}". - throw new MissingResourceException(Messages.getString("logging.8", //$NON-NLS-1$ - resourceBundleName), resourceBundleName, null); + throw new MissingResourceException("Failed to load the specified resource bundle \"" + + resourceBundleName + "\"", resourceBundleName, null); } /** @@ -394,11 +391,7 @@ public class Logger { if (current.equals(resourceBundleName)) { return; } else { - // logging.9=The specified resource bundle name "{0}" is - // inconsistent with the existing one "{1}". - throw new IllegalArgumentException(Messages.getString( - "logging.9", //$NON-NLS-1$ - resourceBundleName, current)); + throw new IllegalArgumentException("Resource bundle name '" + resourceBundleName + "' is inconsistent with the existing '" + current + "'"); } } @@ -458,8 +451,7 @@ public class Logger { */ public void addHandler(Handler handler) { if (handler == null) { - // logging.A=The 'handler' parameter is null. - throw new NullPointerException(Messages.getString("logging.A")); //$NON-NLS-1$ + throw new NullPointerException("handler == null"); } // Anonymous loggers can always add handlers if (this.isNamed) { @@ -655,8 +647,7 @@ public class Logger { */ public void setParent(Logger parent) { if (parent == null) { - // logging.B=The 'parent' parameter is null. - throw new NullPointerException(Messages.getString("logging.B")); //$NON-NLS-1$ + throw new NullPointerException("parent == null"); } // even anonymous loggers are checked diff --git a/logging/src/main/java/java/util/logging/LoggingPermission.java b/logging/src/main/java/java/util/logging/LoggingPermission.java index aa41a2c..5ca9cc9 100644 --- a/logging/src/main/java/java/util/logging/LoggingPermission.java +++ b/logging/src/main/java/java/util/logging/LoggingPermission.java @@ -21,8 +21,6 @@ import java.io.Serializable; import java.security.BasicPermission; import java.security.Guard; -import org.apache.harmony.logging.internal.nls.Messages; - /** * The permission required to control the logging when run with a * {@code SecurityManager}. @@ -51,14 +49,11 @@ public final class LoggingPermission extends BasicPermission implements Guard, */ public LoggingPermission(String name, String actions) { super(name, actions); - if (!"control".equals(name)) { //$NON-NLS-1$ - // logging.6=Name must be "control". - throw new IllegalArgumentException(Messages.getString("logging.6")); //$NON-NLS-1$ + if (!"control".equals(name)) { + throw new IllegalArgumentException("name must be \"control\""); } - if (null != actions && !"".equals(actions)) { //$NON-NLS-1$ - // logging.7=Actions must be either null or the empty string. - throw new IllegalArgumentException(Messages.getString("logging.7")); //$NON-NLS-1$ + if (actions != null && !actions.isEmpty()) { + throw new IllegalArgumentException("actions != null && !actions.isEmpty()"); } } - } diff --git a/logging/src/main/java/java/util/logging/MemoryHandler.java b/logging/src/main/java/java/util/logging/MemoryHandler.java index 3312083..c1b36c8 100644 --- a/logging/src/main/java/java/util/logging/MemoryHandler.java +++ b/logging/src/main/java/java/util/logging/MemoryHandler.java @@ -20,8 +20,6 @@ package java.util.logging; import java.security.AccessController; import java.security.PrivilegedExceptionAction; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A {@code Handler} put the description of log events into a cycled memory * buffer. @@ -92,7 +90,7 @@ public class MemoryHandler extends Handler { super(); String className = this.getClass().getName(); // init target - final String targetName = manager.getProperty(className + ".target"); //$NON-NLS-1$ + final String targetName = manager.getProperty(className + ".target"); try { Class<?> targetClass = AccessController .doPrivileged(new PrivilegedExceptionAction<Class<?>>() { @@ -107,12 +105,10 @@ public class MemoryHandler extends Handler { }); target = (Handler) targetClass.newInstance(); } catch (Exception e) { - // logging.10=Cannot load target handler:{0} - throw new RuntimeException(Messages.getString("logging.10", //$NON-NLS-1$ - targetName)); + throw new RuntimeException("Cannot load target handler '" + targetName + "'"); } // init size - String sizeString = manager.getProperty(className + ".size"); //$NON-NLS-1$ + String sizeString = manager.getProperty(className + ".size"); if (null != sizeString) { try { size = Integer.parseInt(sizeString); @@ -120,20 +116,20 @@ public class MemoryHandler extends Handler { size = DEFAULT_SIZE; } } catch (Exception e) { - printInvalidPropMessage(className + ".size", sizeString, e); //$NON-NLS-1$ + printInvalidPropMessage(className + ".size", sizeString, e); } } // init push level - String pushName = manager.getProperty(className + ".push"); //$NON-NLS-1$ + String pushName = manager.getProperty(className + ".push"); if (null != pushName) { try { push = Level.parse(pushName); } catch (Exception e) { - printInvalidPropMessage(className + ".push", pushName, e); //$NON-NLS-1$ + printInvalidPropMessage(className + ".push", pushName, e); } } // init other properties which are common for all Handler - initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$ + initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size]; } @@ -157,15 +153,14 @@ public class MemoryHandler extends Handler { */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { - // logging.11=Size must be positive. - throw new IllegalArgumentException(Messages.getString("logging.11")); //$NON-NLS-1$ + throw new IllegalArgumentException("size <= 0"); } target.getLevel(); pushLevel.intValue(); this.target = target; this.size = size; this.push = pushLevel; - initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); //$NON-NLS-1$//$NON-NLS-2$ + initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size]; } diff --git a/logging/src/main/java/java/util/logging/SocketHandler.java b/logging/src/main/java/java/util/logging/SocketHandler.java index 0253013..fb854fe 100644 --- a/logging/src/main/java/java/util/logging/SocketHandler.java +++ b/logging/src/main/java/java/util/logging/SocketHandler.java @@ -21,8 +21,6 @@ import java.io.BufferedOutputStream; import java.io.IOException; import java.net.Socket; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A handler that writes log messages to a socket connection. * <p> @@ -110,28 +108,24 @@ public class SocketHandler extends StreamHandler { // Initialize the socket connection and prepare the output stream private void initSocket(String host, String port) throws IOException { // check the validity of the host name - if (null == host || "".equals(host)) { //$NON-NLS-1$ - // logging.C=Illegal host argument. - throw new IllegalArgumentException(Messages.getString("logging.C")); //$NON-NLS-1$ + if (host == null || host.isEmpty()) { + throw new IllegalArgumentException("host == null || host.isEmpty()"); } // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { - // logging.D=Illegal port argument. - throw new IllegalArgumentException(Messages.getString("logging.D")); //$NON-NLS-1$ + throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { - // logging.D=Illegal port argument. - throw new IllegalArgumentException(Messages.getString("logging.D")); //$NON-NLS-1$ + throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { - // logging.E=Failed to establish the network connection. - getErrorManager().error(Messages.getString("logging.E"), e, //$NON-NLS-1$ + getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } @@ -154,8 +148,7 @@ public class SocketHandler extends StreamHandler { this.socket = null; } } catch (Exception e) { - // logging.F=Exception occurred when closing the socket handler. - getErrorManager().error(Messages.getString("logging.F"), e, //$NON-NLS-1$ + getErrorManager().error("Exception occurred when closing the socket handler", e, ErrorManager.CLOSE_FAILURE); } } diff --git a/logging/src/main/java/java/util/logging/StreamHandler.java b/logging/src/main/java/java/util/logging/StreamHandler.java index 7049d45..2a67b98 100644 --- a/logging/src/main/java/java/util/logging/StreamHandler.java +++ b/logging/src/main/java/java/util/logging/StreamHandler.java @@ -22,8 +22,6 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; -import org.apache.harmony.logging.internal.nls.Messages; - /** * A {@code StreamHandler} object writes log messages to an output stream, that * is, objects of the class {@link java.io.OutputStream}. @@ -63,8 +61,7 @@ public class StreamHandler extends Handler { * does not have an associated output stream. */ public StreamHandler() { - initProperties("INFO", null, "java.util.logging.SimpleFormatter", //$NON-NLS-1$//$NON-NLS-2$ - null); + initProperties("INFO", null, "java.util.logging.SimpleFormatter", null); this.os = null; this.writer = null; this.writerNotInitialized = true; @@ -110,19 +107,17 @@ public class StreamHandler extends Handler { public StreamHandler(OutputStream os, Formatter formatter) { this(); if (os == null) { - // logging.2=The OutputStream parameter is null - throw new NullPointerException(Messages.getString("logging.2")); //$NON-NLS-1$ + throw new NullPointerException("os == null"); } if (formatter == null) { - // logging.3=The Formatter parameter is null. - throw new NullPointerException(Messages.getString("logging.3")); //$NON-NLS-1$ + throw new NullPointerException("formatter == null"); } this.os = os; internalSetFormatter(formatter); } // initialize the writer - private void initializeWritter() { + private void initializeWriter() { this.writerNotInitialized = false; if (null == getEncoding()) { this.writer = new OutputStreamWriter(this.os); @@ -144,8 +139,7 @@ public class StreamHandler extends Handler { try { this.writer.write(s); } catch (Exception e) { - // logging.14=Exception occurred when writing to the output stream. - getErrorManager().error(Messages.getString("logging.14"), e, //$NON-NLS-1$ + getErrorManager().error("Exception occurred when writing to the output stream", e, ErrorManager.WRITE_FAILURE); } } @@ -231,7 +225,7 @@ public class StreamHandler extends Handler { void close(boolean closeStream) { if (null != this.os) { if (this.writerNotInitialized) { - initializeWritter(); + initializeWriter(); } write(getFormatter().getTail(this)); try { @@ -242,8 +236,7 @@ public class StreamHandler extends Handler { this.os = null; } } catch (Exception e) { - // logging.15=Exception occurred when closing the output stream. - getErrorManager().error(Messages.getString("logging.15"), e, //$NON-NLS-1$ + getErrorManager().error("Exception occurred when closing the output stream", e, ErrorManager.CLOSE_FAILURE); } } @@ -278,9 +271,7 @@ public class StreamHandler extends Handler { this.os.flush(); } } catch (Exception e) { - // logging.16=Exception occurred while flushing the output - // stream. - getErrorManager().error(Messages.getString("logging.16"), //$NON-NLS-1$ + getErrorManager().error("Exception occurred when flushing the output stream", e, ErrorManager.FLUSH_FAILURE); } } @@ -306,22 +297,19 @@ public class StreamHandler extends Handler { try { if (this.isLoggable(record)) { if (this.writerNotInitialized) { - initializeWritter(); + initializeWriter(); } String msg = null; try { msg = getFormatter().format(record); } catch (Exception e) { - // logging.17=Exception occurred while formatting the log - // record. - getErrorManager().error(Messages.getString("logging.17"), //$NON-NLS-1$ + getErrorManager().error("Exception occurred when formatting the log record", e, ErrorManager.FORMAT_FAILURE); } write(msg); } } catch (Exception e) { - // logging.18=Exception occurred while logging the record. - getErrorManager().error(Messages.getString("logging.18"), e, //$NON-NLS-1$ + getErrorManager().error("Exception occurred when logging the record", e, ErrorManager.GENERIC_FAILURE); } } diff --git a/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java b/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java deleted file mode 100644 index 87535ae..0000000 --- a/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL. - * All changes made to this file manually will be overwritten - * if this tool runs again. Better make changes in the template file. - */ - -// BEGIN android-note -// Redundant code has been removed and is now called from MsgHelp. -// END android-note - -package org.apache.harmony.logging.internal.nls; - - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -// BEGIN android-changed -import org.apache.harmony.luni.util.MsgHelp; -// END android-changed - -/** - * This class retrieves strings from a resource bundle and returns them, - * formatting them with MessageFormat when required. - * <p> - * It is used by the system classes to provide national language support, by - * looking up messages in the <code> - * org.apache.harmony.logging.internal.nls.messages - * </code> - * resource bundle. Note that if this file is not available, or an invalid key - * is looked up, or resource bundle support is not available, the key itself - * will be returned as the associated message. This means that the <em>KEY</em> - * should a reasonable human-readable (english) string. - * - */ -public class Messages { - - // BEGIN android-changed - private static final String sResource = - "org.apache.harmony.logging.internal.nls.messages"; //$NON-NLS-1$ - // END android-changed - - /** - * Retrieves a message which has no arguments. - * - * @param msg - * String the key to look up. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg); - // END android-changed - } - - /** - * Retrieves a message which takes 1 argument. - * - * @param msg - * String the key to look up. - * @param arg - * Object the object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg) { - return getString(msg, new Object[] { arg }); - } - - /** - * Retrieves a message which takes 1 integer argument. - * - * @param msg - * String the key to look up. - * @param arg - * int the integer to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, int arg) { - return getString(msg, new Object[] { Integer.toString(arg) }); - } - - /** - * Retrieves a message which takes 1 character argument. - * - * @param msg - * String the key to look up. - * @param arg - * char the character to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, char arg) { - return getString(msg, new Object[] { String.valueOf(arg) }); - } - - /** - * Retrieves a message which takes 2 arguments. - * - * @param msg - * String the key to look up. - * @param arg1 - * Object an object to insert in the formatted output. - * @param arg2 - * Object another object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg1, Object arg2) { - return getString(msg, new Object[] { arg1, arg2 }); - } - - /** - * Retrieves a message which takes several arguments. - * - * @param msg - * String the key to look up. - * @param args - * Object[] the objects to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object[] args) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg, args); - // END android-changed - } - - // BEGIN android-note - // Duplicate code was dropped in favor of using MsgHelp. - // END android-note -} diff --git a/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties b/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties deleted file mode 100644 index da3945e..0000000 --- a/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties +++ /dev/null @@ -1,52 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# messages for EN locale -logging.0=This method is not currently implemented. -logging.1=Invalid level name: {0}. -logging.10=Cannot load target handler:{0} -logging.11=Size must be positive. -logging.12=Invalid property value for -logging.13=The encoding "{0}" is not supported. -logging.14=Exception occurred when writing to the output stream. -logging.15=Exception occurred when closing the output stream. -logging.16=Exception occurred while flushing the output stream. -logging.17=Exception occurred while formatting the log record. -logging.18=Exception occurred while logging the record. -logging.19=Pattern cannot be empty -logging.1A=Error happened when open log file. -logging.1B=The limit and count property must be larger than 0 and 1, respectively -logging.1C=The 'name' parameter is null. -logging.1D=Cannot parse this name: {0} -logging.1E=Error message - {0} -logging.1F=Exception - {0} -logging.2=The OutputStream parameter is null -logging.20=Loading class "{0}" failed -logging.21=There Can Be Only One logging MX bean. -logging.22=Exception occurred while getting the logging MX bean. -logging.3=The Formatter parameter is null. -logging.4=The 'level' parameter is null. -logging.5=Different version - {0}.{1} -logging.6=Name must be "control". -logging.7=Actions must be either null or the empty string. -logging.8=Failed to load the specified resource bundle "{0}". -logging.9=The specified resource bundle name "{0}" is inconsistent with the existing one "{1}". -logging.A=The 'handler' parameter is null. -logging.B=The 'parent' parameter is null. -logging.C=Illegal host argument. -logging.D=Illegal port argument. -logging.E=Failed to establish the network connection. -logging.F=Exception occured when closing the socket handler. diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java index 91b3e1a..7807768 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java @@ -44,7 +44,6 @@ public class AllTests { suite.addTestSuite(SocketHandlerTest.class); suite.addTestSuite(StreamHandlerTest.class); suite.addTestSuite(XMLFormatterTest.class); - suite.addTestSuite(MessagesTest.class); // $JUnit-END$ return suite; } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java deleted file mode 100644 index e045a4b..0000000 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.apache.harmony.logging.tests.java.util.logging; - -import junit.framework.TestCase; - -import org.apache.harmony.logging.internal.nls.Messages; - -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.logging.ErrorManager; - - - - -public class MessagesTest extends TestCase{ - - - private Messages m = null; - - public void setUp() throws Exception{ - super.setUp(); - m = new Messages(); - - } - - public void tearDown() throws Exception{ - super.tearDown(); - } - - - public void testGetString_String() { - m.getString(new String()); - } - - public void testGetString_StringObject() { - m.getString(new String(), new Object()); - } - - public void testGetString_StringInt() { - m.getString(new String(), 0); - } - - public void testGetString_StringChar() { - m.getString(new String(), 'a'); - } - - public void testGetString_StringObjectObject() { - m.getString(new String(), new Object(), new Object() ); - } - - public void testGetString_StringObjectArray() { - m.getString(new String(), new Object[1]); - } - - -} diff --git a/math/src/main/java/java/math/BigDecimal.java b/math/src/main/java/java/math/BigDecimal.java index 4e4875b..364470a 100644 --- a/math/src/main/java/java/math/BigDecimal.java +++ b/math/src/main/java/java/math/BigDecimal.java @@ -22,8 +22,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import org.apache.harmony.math.internal.nls.Messages; - /** * This class represents immutable integer numbers of arbitrary length. Large * numbers are typically used in security applications and therefore BigIntegers @@ -378,8 +376,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial newScale = (long)scale - Integer.parseInt(scaleString); scale = (int)newScale; if (newScale != scale) { - // math.02=Scale out of range. - throw new NumberFormatException(Messages.getString("math.02")); //$NON-NLS-1$ + throw new NumberFormatException("Scale out of range"); } } // Parsing the unscaled value @@ -523,8 +520,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial */ public BigDecimal(double val) { if (Double.isInfinite(val) || Double.isNaN(val)) { - // math.03=Infinity or NaN - throw new NumberFormatException(Messages.getString("math.03")); //$NON-NLS-1$ + throw new NumberFormatException("Infinity or NaN"); } long bits = Double.doubleToLongBits(val); // IEEE-754 long mantisa; @@ -802,8 +798,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial */ public static BigDecimal valueOf(double val) { if (Double.isInfinite(val) || Double.isNaN(val)) { - // math.03=Infinity or NaN - throw new NumberFormatException(Messages.getString("math.03")); //$NON-NLS-1$ + throw new NumberFormatException("Infinity or NaN"); } return new BigDecimal(Double.toString(val)); } @@ -1113,8 +1108,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial throw new NullPointerException(); } if (divisor.isZero()) { - // math.04=Division by zero - throw new ArithmeticException(Messages.getString("math.04")); //$NON-NLS-1$ + throw new ArithmeticException("Division by zero"); } long diffScale = ((long)this.scale - divisor.scale) - scale; @@ -1289,8 +1283,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial int lastPow = FIVE_POW.length - 1; if (divisor.isZero()) { - // math.04=Division by zero - throw new ArithmeticException(Messages.getString("math.04")); //$NON-NLS-1$ + throw new ArithmeticException("Division by zero"); } if (p.signum() == 0) { return zeroScaledBy(diffScale); @@ -1320,8 +1313,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial } while (true); // If abs(q) != 1 then the quotient is periodic if (!q.abs().equals(BigInteger.ONE)) { - // math.05=Non-terminating decimal expansion; no exact representable decimal result. - throw new ArithmeticException(Messages.getString("math.05")); //$NON-NLS-1$ + throw new ArithmeticException("Non-terminating decimal expansion; no exact representable decimal result"); } // The sign of the is fixed and the quotient will be saved in 'p' if (q.signum() < 0) { @@ -1434,8 +1426,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial int lastPow = TEN_POW.length - 1; if (divisor.isZero()) { - // math.04=Division by zero - throw new ArithmeticException(Messages.getString("math.04")); //$NON-NLS-1$ + throw new ArithmeticException("Division by zero"); } if ((divisor.aproxPrecision() + newScale > this.aproxPrecision() + 1L) || (this.isZero())) { @@ -1544,9 +1535,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial compRemDiv = Math.abs(quotAndRem[1].signum()); } if (compRemDiv > 0) { - // The quotient won't fit in 'mc.precision()' digits - // math.06=Division impossible - throw new ArithmeticException(Messages.getString("math.06")); //$NON-NLS-1$ + throw new ArithmeticException("Division impossible"); } } } @@ -1579,8 +1568,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial } // To check if the result fit in 'mc.precision()' digits if (resultPrecision > mcPrecision) { - // math.06=Division impossible - throw new ArithmeticException(Messages.getString("math.06")); //$NON-NLS-1$ + throw new ArithmeticException("Division impossible"); } integralValue.scale = toIntScale(newScale); integralValue.setUnscaledValue(strippedBI); @@ -1706,14 +1694,12 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial return ONE; } if ((n < 0) || (n > 999999999)) { - // math.07=Invalid Operation - throw new ArithmeticException(Messages.getString("math.07")); //$NON-NLS-1$ + throw new ArithmeticException("Invalid operation"); } long newScale = scale * (long)n; // Let be: this = [u,s] so: this^n = [u^n, s*n] - return ((isZero()) - ? zeroScaledBy(newScale) - : new BigDecimal(getUnscaledValue().pow(n), toIntScale(newScale))); + return isZero() ? zeroScaledBy(newScale) + : new BigDecimal(getUnscaledValue().pow(n), toIntScale(newScale)); } /** @@ -1746,8 +1732,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial } if ((m > 999999999) || ((mcPrecision == 0) && (n < 0)) || ((mcPrecision > 0) && (elength > mcPrecision))) { - // math.07=Invalid Operation - throw new ArithmeticException(Messages.getString("math.07")); //$NON-NLS-1$ + throw new ArithmeticException("Invalid operation"); } if (mcPrecision > 0) { newPrecision = new MathContext( mcPrecision + elength + 1, @@ -2336,7 +2321,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial if (exponent >= 0) { result.insert(end - scale, '.'); } else { - result.insert(begin - 1, "0."); //$NON-NLS-1$ + result.insert(begin - 1, "0."); result.insert(begin + 1, CH_ZEROS, 0, -(int)exponent - 1); } } else { @@ -2380,7 +2365,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial if (exponent >= 0) { result.insert(end - scale, '.'); } else { - result.insert(begin - 1, "0."); //$NON-NLS-1$ + result.insert(begin - 1, "0."); result.insert(begin + 1, CH_ZEROS, 0, -(int)exponent - 1); } } else { @@ -2452,7 +2437,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial if (scale > 0) { delta -= (intStr.length() - begin); if (delta >= 0) { - result.append("0."); //$NON-NLS-1$ + result.append("0."); // To append zeros after the decimal point for (; delta > CH_ZEROS.length; delta -= CH_ZEROS.length) { result.append(CH_ZEROS); @@ -2510,14 +2495,12 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial BigInteger[] integerAndFraction; // An optimization before do a heavy division if ((scale > aproxPrecision()) || (scale > getUnscaledValue().getLowestSetBit())) { - // math.08=Rounding necessary - throw new ArithmeticException(Messages.getString("math.08")); //$NON-NLS-1$ + throw new ArithmeticException("Rounding necessary"); } integerAndFraction = getUnscaledValue().divideAndRemainder(Multiplication.powerOf10(scale)); if (integerAndFraction[1].signum() != 0) { // It exists a non-zero fractional part - // math.08=Rounding necessary - throw new ArithmeticException(Messages.getString("math.08")); //$NON-NLS-1$ + throw new ArithmeticException("Rounding necessary"); } return integerAndFraction[0]; } @@ -2908,8 +2891,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial switch (roundingMode) { case UNNECESSARY: if (fraction != 0) { - // math.08=Rounding necessary - throw new ArithmeticException(Messages.getString("math.08")); //$NON-NLS-1$ + throw new ArithmeticException("Rounding necessary"); } break; case UP: @@ -2964,8 +2946,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial // It fits in the primitive type return bigInteger.longValue(); } - // math.08=Rounding necessary - throw new ArithmeticException(Messages.getString("math.08")); //$NON-NLS-1$ + throw new ArithmeticException("Rounding necessary"); } /** @@ -2998,11 +2979,9 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial */ private static int toIntScale(long longScale) { if (longScale < Integer.MIN_VALUE) { - // math.09=Overflow - throw new ArithmeticException(Messages.getString("math.09")); //$NON-NLS-1$ + throw new ArithmeticException("Overflow"); } else if (longScale > Integer.MAX_VALUE) { - // math.0A=Underflow - throw new ArithmeticException(Messages.getString("math.0A")); //$NON-NLS-1$ + throw new ArithmeticException("Underflow"); } else { return (int)longScale; } diff --git a/math/src/main/java/java/math/BigInt.java b/math/src/main/java/java/math/BigInt.java index 1f3ffdd..d1bd29b 100644 --- a/math/src/main/java/java/math/BigInt.java +++ b/math/src/main/java/java/math/BigInt.java @@ -16,10 +16,8 @@ package java.math; -import org.apache.harmony.math.internal.nls.Messages; -import org.openssl.NativeBN; - import java.util.Random; +import org.openssl.NativeBN; /* * In contrast to BigIntegers this class doesn't fake two's complement representation. @@ -85,12 +83,10 @@ class BigInt while ((e = NativeBN.ERR_get_error()) != 0) { reason = e & 255; if (reason == 103) { - // math.17=BigInteger divide by zero - throw new ArithmeticException(Messages.getString("math.17")); //$NON-NLS-1$ + throw new ArithmeticException("BigInteger division by zero"); } if (reason == 108) { - // math.19=BigInteger not invertible. - throw new ArithmeticException(Messages.getString("math.19")); //$NON-NLS-1$ + throw new ArithmeticException("BigInteger not invertible"); } if (reason == 65) { throw new OutOfMemoryError(); diff --git a/math/src/main/java/java/math/BigInteger.java b/math/src/main/java/java/math/BigInteger.java index c463b48..1fbeb48 100644 --- a/math/src/main/java/java/math/BigInteger.java +++ b/math/src/main/java/java/math/BigInteger.java @@ -29,8 +29,6 @@ import java.io.ObjectOutputStream; import java.util.Random; import java.io.Serializable; -import org.apache.harmony.math.internal.nls.Messages; - /** * This class represents immutable integer numbers of arbitrary length. Large * numbers are typically used in security applications and therefore BigIntegers @@ -220,8 +218,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger(int numBits, Random rnd) { if (numBits < 0) { - // math.1B=numBits must be non-negative - throw new IllegalArgumentException(Messages.getString("math.1B")); //$NON-NLS-1$ + throw new IllegalArgumentException("numBits must be non-negative"); } if (numBits == 0) { sign = 0; @@ -265,8 +262,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger(int bitLength, int certainty, Random rnd) { if (bitLength < 2) { - // math.1C=bitLength < 2 - throw new ArithmeticException(Messages.getString("math.1C")); //$NON-NLS-1$ + throw new ArithmeticException("bitLength < 2"); } bigInt = BigInt.generatePrimeDefault(bitLength, rnd, null); bigIntIsValid = true; @@ -327,12 +323,10 @@ public class BigInteger extends Number implements Comparable<BigInteger>, // !oldReprIsValid } else { if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) { - // math.11=Radix out of range - throw new NumberFormatException(Messages.getString("math.11")); //$NON-NLS-1$ + throw new NumberFormatException("Radix out of range"); } if (val.length() == 0) { - // math.12=Zero length BigInteger - throw new NumberFormatException(Messages.getString("math.12")); //$NON-NLS-1$ + throw new NumberFormatException("Zero-length BigInteger"); } BigInteger.setFromString(this, val, radix); // oldReprIsValid == true; @@ -361,15 +355,13 @@ public class BigInteger extends Number implements Comparable<BigInteger>, if (magnitude == null) { throw new NullPointerException(); } - if ((signum < -1) || (signum > 1)) { - // math.13=Invalid signum value - throw new NumberFormatException(Messages.getString("math.13")); //$NON-NLS-1$ + if (signum < -1 || signum > 1) { + throw new NumberFormatException("Invalid signum value"); } if (signum == 0) { for (byte element : magnitude) { if (element != 0) { - // math.14=signum-magnitude mismatch - throw new NumberFormatException(Messages.getString("math.14")); //$NON-NLS-1$ + throw new NumberFormatException("signum-magnitude mismatch"); } } } @@ -393,8 +385,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger(byte[] val) { if (val.length == 0) { - // math.12=Zero length BigInteger - throw new NumberFormatException(Messages.getString("math.12")); //$NON-NLS-1$ + throw new NumberFormatException("Zero-length BigInteger"); } bigInt = new BigInt(); bigInt.putBigEndianTwosComplement(val); @@ -600,8 +591,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public boolean testBit(int n) { if (n < 0) { - // math.15=Negative bit address - throw new ArithmeticException(Messages.getString("math.15")); //$NON-NLS-1$ + throw new ArithmeticException("n < 0"); } int sign = signum(); if ((sign > 0) && bigIntIsValid && !oldReprIsValid) { @@ -700,8 +690,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, public BigInteger flipBit(int n) { establishOldRepresentation("flipBit"); if (n < 0) { - // math.15=Negative bit address - throw new ArithmeticException(Messages.getString("math.15")); //$NON-NLS-1$ + throw new ArithmeticException("n < 0"); } return BitLevel.flipBit(this, n); } @@ -1062,8 +1051,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger pow(int exp) { if (exp < 0) { - // math.16=Negative exponent - throw new ArithmeticException(Messages.getString("math.16")); //$NON-NLS-1$ + throw new ArithmeticException("exp < 0"); } validate1("pow", this); return new BigInteger(BigInt.exp(bigInt, exp, null)); @@ -1151,8 +1139,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger modInverse(BigInteger m) { if (m.signum() <= 0) { - // math.18=BigInteger: modulus not positive - throw new ArithmeticException(Messages.getString("math.18")); //$NON-NLS-1$ + throw new ArithmeticException("modulus not positive"); } validate2("modInverse", this, m); return new BigInteger(BigInt.modInverse(bigInt, m.bigInt, null)); @@ -1179,8 +1166,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger modPow(BigInteger exponent, BigInteger m) { if (m.signum() <= 0) { - // math.18=BigInteger: modulus not positive - throw new ArithmeticException(Messages.getString("math.18")); //$NON-NLS-1$ + throw new ArithmeticException("modulus not positive"); } BigInteger base; if (exponent.signum() < 0) { @@ -1210,8 +1196,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>, */ public BigInteger mod(BigInteger m) { if (m.signum() <= 0) { - // math.18=BigInteger: modulus not positive - throw new ArithmeticException(Messages.getString("math.18")); //$NON-NLS-1$ + throw new ArithmeticException("modulus not positive"); } validate2("mod", this, m); return new BigInteger(BigInt.modulus(bigInt, m.bigInt, null)); @@ -1239,14 +1224,13 @@ public class BigInteger extends Number implements Comparable<BigInteger>, * a {@code BigInteger} instance. The probability that the returned {@code * BigInteger} is prime is beyond (1-1/2^80). * - * @return smallest integer > {@code this} which is robably prime. + * @return smallest integer > {@code this} which is probably prime. * @throws ArithmeticException * if {@code this < 0}. */ public BigInteger nextProbablePrime() { if (sign < 0) { - // math.1A=start < 0: {0} - throw new ArithmeticException(Messages.getString("math.1A", this)); //$NON-NLS-1$ + throw new ArithmeticException("sign < 0"); } return Primality.nextProbablePrime(this); } diff --git a/math/src/main/java/java/math/Division.java b/math/src/main/java/java/math/Division.java index ce2519d..e93da7e 100644 --- a/math/src/main/java/java/math/Division.java +++ b/math/src/main/java/java/math/Division.java @@ -17,10 +17,6 @@ package java.math; -// BEGIN android-removed -// import org.apache.harmony.math.internal.nls.Messages; -// END android-removed - /** * Static library that provides all operations related with division and modular * arithmetic to {@link BigInteger}. Some methods are provided in both mutable diff --git a/math/src/main/java/java/math/MathContext.java b/math/src/main/java/java/math/MathContext.java index cf1d4eb..ba33a88 100644 --- a/math/src/main/java/java/math/MathContext.java +++ b/math/src/main/java/java/math/MathContext.java @@ -22,8 +22,6 @@ import java.io.ObjectInputStream; import java.io.Serializable; import java.io.StreamCorruptedException; -import org.apache.harmony.math.internal.nls.Messages; - /** * Immutable objects describing settings such as rounding mode and digit * precision for the numerical operations provided by class {@link BigDecimal}. @@ -130,12 +128,10 @@ public final class MathContext implements Serializable { */ public MathContext(int precision, RoundingMode roundingMode) { if (precision < 0) { - // math.0C=Digits < 0 - throw new IllegalArgumentException(Messages.getString("math.0C")); //$NON-NLS-1$ + throw new IllegalArgumentException("precision < 0"); } if (roundingMode == null) { - // math.0D=null RoundingMode - throw new NullPointerException(Messages.getString("math.0D")); //$NON-NLS-1$ + throw new NullPointerException("roundingMode == null"); } this.precision = precision; this.roundingMode = roundingMode; @@ -162,8 +158,7 @@ public final class MathContext implements Serializable { int digit; // It will contain the digit parsed if ((charVal.length < 27) || (charVal.length > 45)) { - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } // Parsing "precision=" String for (i = 0; (i < chPrecision.length) && (charVal[i] == chPrecision[i]); i++) { @@ -171,14 +166,12 @@ public final class MathContext implements Serializable { } if (i < chPrecision.length) { - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } // Parsing the value for "precision="... digit = Character.digit(charVal[i], 10); if (digit == -1) { - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } // BEGIN android-changed this.precision = digit; @@ -194,14 +187,12 @@ public final class MathContext implements Serializable { break; } // It isn't a valid digit, and isn't a white space - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } // Accumulating the value parsed this.precision = this.precision * 10 + digit; if (this.precision < 0) { - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } i++; } while (true); @@ -212,8 +203,7 @@ public final class MathContext implements Serializable { } if (j < chRoundingMode.length) { - // math.0E=bad string format - throw new IllegalArgumentException(Messages.getString("math.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("Bad string format"); } // Parsing the value for "roundingMode"... this.roundingMode = RoundingMode.valueOf(String.valueOf(charVal, i, @@ -314,16 +304,13 @@ public final class MathContext implements Serializable { * @throws StreamCorruptedException * if {@code roundingMode == null} */ - private void readObject(ObjectInputStream s) throws IOException, - ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); if (precision < 0) { - // math.0F=bad precision value - throw new StreamCorruptedException(Messages.getString("math.0F")); //$NON-NLS-1$ + throw new StreamCorruptedException("precision < 0"); } if (roundingMode == null) { - // math.10=null roundingMode - throw new StreamCorruptedException(Messages.getString("math.10")); //$NON-NLS-1$ + throw new StreamCorruptedException("roundingMode == null"); } } diff --git a/math/src/main/java/java/math/Multiplication.java b/math/src/main/java/java/math/Multiplication.java index 05c4605..25fd31c 100644 --- a/math/src/main/java/java/math/Multiplication.java +++ b/math/src/main/java/java/math/Multiplication.java @@ -17,8 +17,6 @@ package java.math; -import org.apache.harmony.math.internal.nls.Messages; - /** * Static library that provides all multiplication of {@link BigInteger} methods. */ @@ -142,8 +140,7 @@ class Multiplication { long byteArraySize = 1 + (long)(exp / 2.4082399653118496); if (byteArraySize > Runtime.getRuntime().freeMemory()) { - // math.01=power of ten too big - throw new OutOfMemoryError(Messages.getString("math.01")); //$NON-NLS-1$ + throw new OutOfMemoryError(); } if (exp <= Integer.MAX_VALUE) { // To calculate: 5^exp * 2^exp diff --git a/math/src/main/java/java/math/RoundingMode.java b/math/src/main/java/java/math/RoundingMode.java index b51564f..f4c181e 100644 --- a/math/src/main/java/java/math/RoundingMode.java +++ b/math/src/main/java/java/math/RoundingMode.java @@ -17,8 +17,6 @@ package java.math; -import org.apache.harmony.math.internal.nls.Messages; - /** * Specifies the rounding behavior for operations whose results cannot be * represented exactly. @@ -118,8 +116,7 @@ public enum RoundingMode { case BigDecimal.ROUND_UP: return UP; default: - // math.00=Invalid rounding mode - throw new IllegalArgumentException(Messages.getString("math.00")); //$NON-NLS-1$ + throw new IllegalArgumentException("Invalid rounding mode"); } } } diff --git a/math/src/main/java/org/apache/harmony/math/internal/nls/Messages.java b/math/src/main/java/org/apache/harmony/math/internal/nls/Messages.java deleted file mode 100644 index 4b0075a..0000000 --- a/math/src/main/java/org/apache/harmony/math/internal/nls/Messages.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL. - * All changes made to this file manually will be overwritten - * if this tool runs again. Better make changes in the template file. - */ - -// BEGIN android-note -// Redundant code has been removed and is now called from MsgHelp. -// END android-note - -package org.apache.harmony.math.internal.nls; - -// BEGIN android-added -import org.apache.harmony.luni.util.MsgHelp; -// END android-added - -/** - * This class retrieves strings from a resource bundle and returns them, - * formatting them with MessageFormat when required. - * <p> - * It is used by the system classes to provide national language support, by - * looking up messages in the <code> - * org.apache.harmony.math.internal.nls.messages - * </code> - * resource bundle. Note that if this file is not available, or an invalid key - * is looked up, or resource bundle support is not available, the key itself - * will be returned as the associated message. This means that the <em>KEY</em> - * should a reasonable human-readable (english) string. - * - */ -public class Messages { - - // BEGIN android-changed - private static final String sResource = - "org.apache.harmony.math.internal.nls.messages"; - // END android-changed - - /** - * Retrieves a message which has no arguments. - * - * @param msg - * String the key to look up. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg); - // END android-changed - } - - /** - * Retrieves a message which takes 1 argument. - * - * @param msg - * String the key to look up. - * @param arg - * Object the object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg) { - return getString(msg, new Object[] { arg }); - } - - /** - * Retrieves a message which takes 1 integer argument. - * - * @param msg - * String the key to look up. - * @param arg - * int the integer to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, int arg) { - return getString(msg, new Object[] { Integer.toString(arg) }); - } - - /** - * Retrieves a message which takes 1 character argument. - * - * @param msg - * String the key to look up. - * @param arg - * char the character to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, char arg) { - return getString(msg, new Object[] { String.valueOf(arg) }); - } - - /** - * Retrieves a message which takes 2 arguments. - * - * @param msg - * String the key to look up. - * @param arg1 - * Object an object to insert in the formatted output. - * @param arg2 - * Object another object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg1, Object arg2) { - return getString(msg, new Object[] { arg1, arg2 }); - } - - /** - * Retrieves a message which takes several arguments. - * - * @param msg - * String the key to look up. - * @param args - * Object[] the objects to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object[] args) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg, args); - // END android-changed - } - - // BEGIN android-note - // Duplicate code was dropped in favor of using MsgHelp. - // END android-note -} diff --git a/math/src/main/java/org/apache/harmony/math/internal/nls/messages.properties b/math/src/main/java/org/apache/harmony/math/internal/nls/messages.properties deleted file mode 100644 index 0a40a43..0000000 --- a/math/src/main/java/org/apache/harmony/math/internal/nls/messages.properties +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# messages for EN locale -math.00=Invalid rounding mode -math.01=power of ten too big -math.02=Scale out of range. -math.03=Infinite or NaN -math.04=Division by zero -math.05=Non-terminating decimal expansion; no exact representable decimal result. -math.06=Division impossible -math.07=Invalid Operation -math.08=Rounding necessary -math.09=Overflow -math.0A=Underflow -math.0B=null unscaled value -math.0C=Digits < 0 -math.0D=null RoundingMode -math.0E=bad string format -math.0F=bad precision value -math.10=null roundingMode -math.1B=numBits must be non-negative -math.1C=bitLength < 2 -math.11=Radix out of range -math.12=Zero length BigInteger -math.13=Invalid signum value -math.14=signum-magnitude mismatch -math.15=Negative bit address -math.16=Negative exponent -math.17=BigInteger divide by zero -math.18=BigInteger: modulus not positive -math.19=BigInteger not invertible. -math.1A=start < 0: {0} diff --git a/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java b/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java index dc243cc..393cad5 100644 --- a/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java +++ b/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java @@ -21,8 +21,6 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * A converter that can convert a byte sequence from a charset into a 16-bit * Unicode character sequence. @@ -138,12 +136,10 @@ public abstract class CharsetDecoder { protected CharsetDecoder(Charset charset, float averageCharsPerByte, float maxCharsPerByte) { if (averageCharsPerByte <= 0 || maxCharsPerByte <= 0) { - // niochar.00=Characters number for one byte must be positive. - throw new IllegalArgumentException(Messages.getString("niochar.00")); //$NON-NLS-1$ + throw new IllegalArgumentException("averageCharsPerByte and maxCharsPerByte must be positive"); } if (averageCharsPerByte > maxCharsPerByte) { - // niochar.01=averageCharsPerByte is greater than maxCharsPerByte - throw new IllegalArgumentException(Messages.getString("niochar.01")); //$NON-NLS-1$ + throw new IllegalArgumentException("averageCharsPerByte is greater than maxCharsPerByte"); } averChars = averageCharsPerByte; maxChars = maxCharsPerByte; @@ -151,7 +147,7 @@ public abstract class CharsetDecoder { status = INIT; malformAction = CodingErrorAction.REPORT; unmapAction = CodingErrorAction.REPORT; - replace = "\ufffd"; //$NON-NLS-1$ + replace = "\ufffd"; } /** @@ -692,14 +688,11 @@ public abstract class CharsetDecoder { * mentioned above. */ public final CharsetDecoder replaceWith(String newReplacement) { - if (null == newReplacement || newReplacement.length() == 0) { - // niochar.06=Replacement string cannot be null or empty. - throw new IllegalArgumentException(Messages.getString("niochar.06")); //$NON-NLS-1$ + if (newReplacement == null || newReplacement.isEmpty()) { + throw new IllegalArgumentException("Replacement string cannot be null or empty"); } if (newReplacement.length() > maxChars) { - // niochar.07=Replacement string's length cannot be larger than max - // characters per byte. - throw new IllegalArgumentException(Messages.getString("niochar.07")); //$NON-NLS-1$ + throw new IllegalArgumentException("Replacement string cannot be longer than max characters per byte"); } replace = newReplacement; implReplaceWith(newReplacement); diff --git a/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java b/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java index f24be92..daf2c08 100644 --- a/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java +++ b/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java @@ -20,8 +20,7 @@ import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.CharBuffer; - -import org.apache.harmony.niochar.internal.nls.Messages; +import java.util.Arrays; /** * A converter that can converts a 16-bit Unicode character sequence to a byte @@ -168,12 +167,10 @@ public abstract class CharsetEncoder { protected CharsetEncoder(Charset cs, float averageBytesPerChar, float maxBytesPerChar, byte[] replacement) { if (averageBytesPerChar <= 0 || maxBytesPerChar <= 0) { - // niochar.02=Bytes number for one character must be positive. - throw new IllegalArgumentException(Messages.getString("niochar.02")); //$NON-NLS-1$ + throw new IllegalArgumentException("averageBytesPerChar and maxBytesPerChar must both be positive"); } if (averageBytesPerChar > maxBytesPerChar) { - // niochar.03=averageBytesPerChar is greater than maxBytesPerChar. - throw new IllegalArgumentException(Messages.getString("niochar.03")); //$NON-NLS-1$ + throw new IllegalArgumentException("averageBytesPerChar is greater than maxBytesPerChar"); } this.cs = cs; averBytes = averageBytesPerChar; @@ -221,8 +218,7 @@ public abstract class CharsetEncoder { status = INIT; } if (status != INIT) { - // niochar.0B=Another encoding process is ongoing\! - throw new IllegalStateException(Messages.getString("niochar.0B")); //$NON-NLS-1$ + throw new IllegalStateException("encoding already in progress"); } CodingErrorAction malformBak = malformAction; CodingErrorAction unmapBak = unmapAction; @@ -688,9 +684,8 @@ public abstract class CharsetEncoder { * if the given newAction is null. */ public final CharsetEncoder onMalformedInput(CodingErrorAction newAction) { - if (null == newAction) { - // niochar.0C=Action on malformed input error cannot be null\! - throw new IllegalArgumentException(Messages.getString("niochar.0C")); //$NON-NLS-1$ + if (newAction == null) { + throw new IllegalArgumentException("newAction == null"); } malformAction = newAction; implOnMalformedInput(newAction); @@ -710,11 +705,9 @@ public abstract class CharsetEncoder { * @throws IllegalArgumentException * if the given newAction is null. */ - public final CharsetEncoder onUnmappableCharacter( - CodingErrorAction newAction) { - if (null == newAction) { - // niochar.0D=Action on unmappable character error cannot be null\! - throw new IllegalArgumentException(Messages.getString("niochar.0D")); //$NON-NLS-1$ + public final CharsetEncoder onUnmappableCharacter(CodingErrorAction newAction) { + if (newAction == null) { + throw new IllegalArgumentException("newAction == null"); } unmapAction = newAction; implOnUnmappableCharacter(newAction); @@ -742,18 +735,16 @@ public abstract class CharsetEncoder { * the replacement byte array, cannot be null or empty, its * length cannot be larger than <code>maxBytesPerChar</code>, * and it must be legal replacement, which can be justified by - * calling <code>isLegalReplacement(byte[] repl)</code>. + * calling <code>isLegalReplacement(byte[] replacement)</code>. * @return this encoder. * @throws IllegalArgumentException * if the given replacement cannot satisfy the requirement * mentioned above. */ public final CharsetEncoder replaceWith(byte[] replacement) { - if (null == replacement || 0 == replacement.length - || maxBytes < replacement.length + if (replacement == null || replacement.length == 0 || maxBytes < replacement.length || !isLegalReplacement(replacement)) { - // niochar.0E=Replacement is illegal - throw new IllegalArgumentException(Messages.getString("niochar.0E")); //$NON-NLS-1$ + throw new IllegalArgumentException("bad replacement: " + Arrays.toString(replacement)); } replace = replacement; implReplaceWith(replacement); diff --git a/nio_char/src/main/java/java/nio/charset/CoderResult.java b/nio_char/src/main/java/java/nio/charset/CoderResult.java index 47df0dd..880d9fb 100644 --- a/nio_char/src/main/java/java/nio/charset/CoderResult.java +++ b/nio_char/src/main/java/java/nio/charset/CoderResult.java @@ -20,8 +20,6 @@ import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.util.WeakHashMap; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * Used to indicate the result of encoding/decoding. There are four types of * results: @@ -124,9 +122,7 @@ public class CoderResult { return r; } } - // niochar.08=The length must be positive: {0}. - throw new IllegalArgumentException(Messages.getString( - "niochar.08", length)); //$NON-NLS-1$ + throw new IllegalArgumentException("Length must be greater than 0; was " + length); } /** @@ -154,9 +150,7 @@ public class CoderResult { return r; } } - // niochar.08=The length must be positive: {0}. - throw new IllegalArgumentException(Messages.getString( - "niochar.08", length)); //$NON-NLS-1$ + throw new IllegalArgumentException("Length must be greater than 0; was " + length); } /** @@ -216,14 +210,10 @@ public class CoderResult { * if this result is an overflow or underflow. */ public int length() throws UnsupportedOperationException { - if (this.type == TYPE_MALFORMED_INPUT - || this.type == TYPE_UNMAPPABLE_CHAR) { + if (this.type == TYPE_MALFORMED_INPUT || this.type == TYPE_UNMAPPABLE_CHAR) { return this.length; } - // niochar.09=The length of the erroneous input is only meaningful to - // a malformed-input error or an unmappble character error - throw new UnsupportedOperationException(Messages - .getString("niochar.09")); //$NON-NLS-1$ + throw new UnsupportedOperationException("length meaningless for " + toString()); } /** diff --git a/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java b/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java index fad9fa6..d1c71ea 100644 --- a/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java +++ b/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java @@ -17,8 +17,6 @@ package java.nio.charset; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * An {@code IllegalCharsetNameException} is thrown when an illegal charset name * is encountered. @@ -42,15 +40,12 @@ public class IllegalCharsetNameException extends IllegalArgumentException { * the encountered illegal charset name. */ public IllegalCharsetNameException(String charset) { - // niochar.0F=The illegal charset name is "{0}". - super(Messages.getString("niochar.0F", charset)); //$NON-NLS-1$ + super(charset); this.charsetName = charset; } /** - * Gets the encountered illegal charset name. - * - * @return the encountered illegal charset name. + * Returns the encountered illegal charset name. */ public String getCharsetName() { return this.charsetName; diff --git a/nio_char/src/main/java/java/nio/charset/MalformedInputException.java b/nio_char/src/main/java/java/nio/charset/MalformedInputException.java index 0a93728..aa853bf 100644 --- a/nio_char/src/main/java/java/nio/charset/MalformedInputException.java +++ b/nio_char/src/main/java/java/nio/charset/MalformedInputException.java @@ -17,8 +17,6 @@ package java.nio.charset; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * A {@code MalformedInputException} is thrown when a malformed input is * encountered, for example if a byte sequence is illegal for the given charset. @@ -53,14 +51,8 @@ public class MalformedInputException extends CharacterCodingException { return this.inputLength; } - /** - * Gets a message describing this exception. - * - * @return a message describing this exception. - */ @Override public String getMessage() { - // niochar.05=Malformed input length is {0}. - return Messages.getString("niochar.05", this.inputLength); //$NON-NLS-1$ + return "Length: " + inputLength; } } diff --git a/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java b/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java index db23a6f..b929023 100644 --- a/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java +++ b/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java @@ -17,8 +17,6 @@ package java.nio.charset; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * An {@code UnmappableCharacterException} is thrown when an unmappable * character for the given charset is encountered. @@ -45,22 +43,14 @@ public class UnmappableCharacterException extends CharacterCodingException { } /** - * Gets the length of the unmappable character. - * - * @return the length of the unmappable character. + * Returns the length of the unmappable character. */ public int getInputLength() { return this.inputLength; } - /** - * Gets a message describing this exception. - * - * @return a message describing this exception. - */ @Override public String getMessage() { - // niochar.0A=The unmappable character length is {0}. - return Messages.getString("niochar.0A", this.inputLength); //$NON-NLS-1$ + return "Length: " + inputLength; } } diff --git a/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java b/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java index b5985b4..9bfdcfe 100644 --- a/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java +++ b/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java @@ -17,8 +17,6 @@ package java.nio.charset; -import org.apache.harmony.niochar.internal.nls.Messages; - /** * An {@code UnsupportedCharsetException} is thrown when an unsupported charset * name is encountered. @@ -42,8 +40,7 @@ public class UnsupportedCharsetException extends IllegalArgumentException { * the encountered unsupported charset name. */ public UnsupportedCharsetException(String charset) { - // niochar.04=The unsupported charset name is "{0}". - super(Messages.getString("niochar.04", charset)); //$NON-NLS-1$ + super(charset); this.charsetName = charset; } diff --git a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java b/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java deleted file mode 100644 index f2fb652..0000000 --- a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL. - * All changes made to this file manually will be overwritten - * if this tool runs again. Better make changes in the template file. - */ - -// BEGIN android-note -// Redundant code has been removed and is now called from MsgHelp. -// END android-note - -package org.apache.harmony.niochar.internal.nls; - - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -// BEGIN android-changed -import org.apache.harmony.luni.util.MsgHelp; -// END android-changed - -/** - * This class retrieves strings from a resource bundle and returns them, - * formatting them with MessageFormat when required. - * <p> - * It is used by the system classes to provide national language support, by - * looking up messages in the <code> - * org.apache.harmony.niochar.internal.nls.messages - * </code> - * resource bundle. Note that if this file is not available, or an invalid key - * is looked up, or resource bundle support is not available, the key itself - * will be returned as the associated message. This means that the <em>KEY</em> - * should a reasonable human-readable (english) string. - * - */ -public class Messages { - - // BEGIN android-changed - private static final String sResource = - "org.apache.harmony.niochar.internal.nls.messages"; //$NON-NLS-1$ - // END android-changed - - /** - * Retrieves a message which has no arguments. - * - * @param msg - * String the key to look up. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg); - // END android-changed - } - - /** - * Retrieves a message which takes 1 argument. - * - * @param msg - * String the key to look up. - * @param arg - * Object the object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg) { - return getString(msg, new Object[] { arg }); - } - - /** - * Retrieves a message which takes 1 integer argument. - * - * @param msg - * String the key to look up. - * @param arg - * int the integer to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, int arg) { - return getString(msg, new Object[] { Integer.toString(arg) }); - } - - /** - * Retrieves a message which takes 1 character argument. - * - * @param msg - * String the key to look up. - * @param arg - * char the character to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, char arg) { - return getString(msg, new Object[] { String.valueOf(arg) }); - } - - /** - * Retrieves a message which takes 2 arguments. - * - * @param msg - * String the key to look up. - * @param arg1 - * Object an object to insert in the formatted output. - * @param arg2 - * Object another object to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object arg1, Object arg2) { - return getString(msg, new Object[] { arg1, arg2 }); - } - - /** - * Retrieves a message which takes several arguments. - * - * @param msg - * String the key to look up. - * @param args - * Object[] the objects to insert in the formatted output. - * @return String the message for that key in the system message bundle. - */ - static public String getString(String msg, Object[] args) { - // BEGIN android-changed - return MsgHelp.getString(sResource, msg, args); - // END android-changed - } - - // BEGIN android-note - // Duplicate code was dropped in favor of using MsgHelp. - // END android-note -} - diff --git a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/messages.properties b/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/messages.properties deleted file mode 100644 index 6737e2b..0000000 --- a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/messages.properties +++ /dev/null @@ -1,32 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# messages for EN locale -niochar.00=Characters number for one byte must be positive. -niochar.01=averageCharsPerByte is greater than maxCharsPerByte -niochar.02=Bytes number for one character must be positive. -niochar.03=averageBytesPerChar is greater than maxBytesPerChar. -niochar.04=The unsupported charset name is "{0}". -niochar.05=Malformed input length is {0}. -niochar.06=Replacement string cannot be null or empty. -niochar.07=Replacement string's length cannot be larger than max characters per byte. -niochar.08=The length must be positive: {0}. -niochar.09=The length of the erroneous input is only meaningful to a malformed-input error or an unmappble character error -niochar.0A=The unmappable character length is {0}. -niochar.0B=Another encoding process is ongoing\! -niochar.0C=Action on malformed input error cannot be null\! -niochar.0D=Action on unmappable character error cannot be null\! -niochar.0E=Replacement is illegal -niochar.0F=The illegal charset name is "{0}". |