diff options
Diffstat (limited to 'java/common/src')
4 files changed, 90 insertions, 7 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java b/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java index 6f9d872f98..b2bcc1836e 100644 --- a/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java +++ b/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java @@ -24,6 +24,7 @@ import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import org.apache.qpid.transport.util.Logger; +import org.apache.qpid.util.SystemUtils; /** * Constants for the various properties clients can @@ -88,11 +89,11 @@ public class ConnectionStartProperties fullSystemInfo.append(", "); fullSystemInfo.append(System.getProperty("java.vendor")); fullSystemInfo.append(", "); - fullSystemInfo.append(System.getProperty("os.arch")); + fullSystemInfo.append(SystemUtils.getOSArch()); fullSystemInfo.append(", "); - fullSystemInfo.append(System.getProperty("os.name")); + fullSystemInfo.append(SystemUtils.getOSName()); fullSystemInfo.append(", "); - fullSystemInfo.append(System.getProperty("os.version")); + fullSystemInfo.append(SystemUtils.getOSVersion()); fullSystemInfo.append(", "); fullSystemInfo.append(System.getProperty("sun.os.patch.level")); diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java index 06a43e21c6..0ab195ced8 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java +++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java @@ -26,6 +26,7 @@ import org.apache.qpid.transport.Receiver; import org.apache.qpid.transport.TransportException; import org.apache.qpid.transport.network.Ticker; import org.apache.qpid.transport.util.Logger; +import org.apache.qpid.util.SystemUtils; import javax.net.ssl.SSLSocket; import java.io.IOException; @@ -57,8 +58,7 @@ final class IoReceiver implements Runnable, Closeable private Ticker _ticker; static { - String osName = System.getProperty("os.name"); - shutdownBroken = osName == null ? false : osName.matches("(?i).*windows.*"); + shutdownBroken = SystemUtils.isWindows(); } public IoReceiver(Socket socket, Receiver<ByteBuffer> receiver, int bufferSize, long timeout) diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 7362099070..f48103c650 100644 --- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -129,7 +129,6 @@ public class FileUtils StringBuffer inBuffer = new StringBuffer(); - String line; int read; while ((read = is.read(data)) != -1) @@ -157,6 +156,7 @@ public class FileUtils * * @return An input stream for the file or resource, or null if one could not be opened. */ + @SuppressWarnings("resource") public static InputStream openFileOrDefaultResource(String filename, String defaultResource, ClassLoader cl) { InputStream is = null; @@ -173,7 +173,6 @@ public class FileUtils { is = null; } - if (is == null) { // failed on filesystem, so try on classpath @@ -332,6 +331,8 @@ public class FileUtils public static class UnableToCopyException extends Exception { + private static final long serialVersionUID = 956249157141857044L; + UnableToCopyException(String msg) { super(msg); diff --git a/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java b/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java new file mode 100644 index 0000000000..55c7ae9b96 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/util/SystemUtils.java @@ -0,0 +1,81 @@ +/* + * + * 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.qpid.util; + +/** + * SystemUtils provides some simple helper methods for working with the current + * Operating System. + * + * It follows the convention of wrapping all checked exceptions as runtimes, so + * code using these methods is free of try-catch blocks but does not expect to + * recover from errors. + */ +public class SystemUtils +{ + + public static final String UNKNOWN_OS = "unknown"; + public static final String UNKNOWN_VERSION = "na"; + public static final String UNKNOWN_ARCH = "unknown"; + + private static final String _osName = System.getProperty("os.name", UNKNOWN_OS); + private static final String _osVersion = System.getProperty("os.version", UNKNOWN_VERSION); + private static final String _osArch = System.getProperty("os.arch", UNKNOWN_ARCH); + + private static final boolean _isWindows = _osName.toLowerCase().contains("windows"); + + private SystemUtils() + { + } + + public final static String getOSName() + { + return _osName; + } + + public final static String getOSVersion() + { + return _osVersion; + } + + public final static String getOSArch() + { + return _osArch; + } + + public final static boolean isWindows() + { + return _isWindows; + } + + public final static String getOSConfigSuffix() + { + if (_osName.contains(" ")) + { + return _osName.substring(0, _osName.indexOf(' ')).toLowerCase(); + } + return _osName; + } + + public final static String getOSString() + { + return _osName + " " + _osVersion + " " + _osArch; + } +} |