byte.
* @exception IOException if an I/O error occurs.
*/
+ @Override
public void write(int b) throws IOException {
out.write(b);
}
@@ -95,6 +98,7 @@ class FilterOutputStream extends OutputStream {
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#write(byte[], int, int)
*/
+ @Override
public void write(byte b[]) throws IOException {
write(b, 0, b.length);
}
@@ -119,6 +123,7 @@ class FilterOutputStream extends OutputStream {
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#write(int)
*/
+ @Override
public void write(byte b[], int off, int len) throws IOException {
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
throw new IndexOutOfBoundsException();
@@ -138,6 +143,7 @@ class FilterOutputStream extends OutputStream {
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
+ @Override
public void flush() throws IOException {
out.flush();
}
@@ -154,13 +160,40 @@ class FilterOutputStream extends OutputStream {
* @see java.io.FilterOutputStream#flush()
* @see java.io.FilterOutputStream#out
*/
- @SuppressWarnings("try")
+ @Override
public void close() throws IOException {
- if (closed)
+ if (closed) {
return;
+ }
closed = true;
- try (OutputStream ostream = out) {
+
+ Throwable flushException = null;
+ try {
flush();
+ } catch (Throwable e) {
+ flushException = e;
+ throw e;
+ } finally {
+ if (flushException == null) {
+ out.close();
+ } else {
+ try {
+ out.close();
+ } catch (Throwable closeException) {
+ // evaluate possible precedence of flushException over closeException
+ if ((flushException instanceof ThreadDeath) &&
+ !(closeException instanceof ThreadDeath)) {
+ flushException.addSuppressed(closeException);
+ throw (ThreadDeath) flushException;
+ }
+
+ if (flushException != closeException) {
+ closeException.addSuppressed(flushException);
+ }
+
+ throw closeException;
+ }
+ }
}
}
}
diff --git a/jdk/src/java.base/share/classes/java/io/StringWriter.java b/jdk/src/java.base/share/classes/java/io/StringWriter.java
index 63ca2f0e0f2..c62d82f4ea8 100644
--- a/jdk/src/java.base/share/classes/java/io/StringWriter.java
+++ b/jdk/src/java.base/share/classes/java/io/StringWriter.java
@@ -109,7 +109,7 @@ public class StringWriter extends Writer {
* @param len Number of characters to write
*/
public void write(String str, int off, int len) {
- buf.append(str.substring(off, off + len));
+ buf.append(str, off, off + len);
}
/**
diff --git a/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
index 93b1093df7b..a9216000731 100644
--- a/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
+++ b/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
@@ -515,8 +515,12 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
+ s.length());
int len = end - start;
ensureCapacityInternal(count + len);
- for (int i = start, j = count; i < end; i++, j++)
- value[j] = s.charAt(i);
+ if (s instanceof String) {
+ ((String)s).getChars(start, end, value, count);
+ } else {
+ for (int i = start, j = count; i < end; i++, j++)
+ value[j] = s.charAt(i);
+ }
count += len;
return this;
}
diff --git a/jdk/src/java.base/share/classes/java/net/NetworkInterface.java b/jdk/src/java.base/share/classes/java/net/NetworkInterface.java
index 3376bafdf20..81da1c0cf8f 100644
--- a/jdk/src/java.base/share/classes/java/net/NetworkInterface.java
+++ b/jdk/src/java.base/share/classes/java/net/NetworkInterface.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,14 @@
package java.net;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.NoSuchElementException;
-import sun.security.action.*;
import java.security.AccessController;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
/**
* This class represents a Network Interface made up of a name,
@@ -95,8 +99,8 @@ public final class NetworkInterface {
}
/**
- * Convenience method to return an Enumeration with all or a
- * subset of the InetAddresses bound to this network interface.
+ * Get an Enumeration with all or a subset of the InetAddresses bound to
+ * this network interface.
*
* If there is a security manager, its {@code checkConnect}
* method is called for each InetAddress. Only InetAddresses where
@@ -104,53 +108,56 @@ public final class NetworkInterface {
* will be returned in the Enumeration. However, if the caller has the
* {@link NetPermission}("getNetworkInformation") permission, then all
* InetAddresses are returned.
+ *
* @return an Enumeration object with all or a subset of the InetAddresses
* bound to this network interface
+ * @see #inetAddresses()
*/
public Enumeration
+ * If there is a security manager, its {@code checkConnect}
+ * method is called for each InetAddress. Only InetAddresses where
+ * the {@code checkConnect} doesn't throw a SecurityException will be
+ * returned in the Stream. However, if the caller has the
+ * {@link NetPermission}("getNetworkInformation") permission, then all
+ * InetAddresses are returned.
+ *
+ * @return a Stream object with all or a subset of the InetAddresses
+ * bound to this network interface
+ * @since 1.9
+ */
+ public Stream The collection should not be modified (see {@link #add}) during the
+ * execution of the terminal stream operation. Otherwise, the result of the
+ * terminal stream operation is undefined.
+ *
+ * @implSpec
+ * The default implementation creates a stream whose source is derived from
+ * the enumeration returned from a call to {@link #elements()}.
+ *
+ * @return a stream of all the Permissions.
+ * @since 1.9
+ */
+ public Stream The iterator returned from a call to {@link Enumeration#asIterator()}
+ * does not support removal of elements from the specified collection. This
+ * is necessary to avoid unintentionally increasing the capabilities of the
+ * returned enumeration.
+ *
* @param The assumption is made that assistive technology classes are supplied
- * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
- * on the class path
- * (and therefore can be loaded using the class loader returned by
- * a call to
- * If a system property named
- * If there is no
- * Also loads additional classes into the VM, using the property
- * 'assistive_technologies' specified in the Sun reference
- * implementation by a line in the 'accessibility.properties'
- * file. The form is "assistive_technologies=..." where
- * the "..." is a comma-separated list of assistive technology
- * classes to load. Each class is loaded in the order given
- * and a single instance of each is created using
- * Class.forName(class).newInstance(). This is done just after
- * the AWT toolkit is created. All errors are handled via an
- * AWTError exception.
- * @return the default toolkit.
+ * If this Toolkit is not a headless implementation and if they exist, service
+ * providers of {@link javax.accessibility.AccessibilityProvider} will be loaded
+ * if specified by the system property
+ * {@code javax.accessibility.assistive_technologies}.
+ *
+ * An example of setting this property is to invoke Java with
+ * {@code -Djavax.accessibility.assistive_technologies=MyServiceProvider}.
+ * In addition to MyServiceProvider other service providers can be specified
+ * using a comma separated list. Service providers are loaded after the AWT
+ * toolkit is created. All errors are handled via an AWTError exception.
+ *
+ * The names specified in the assistive_technologies property are used to query
+ * each service provider implementation. If the requested name matches the
+ * {@linkplain AccessibilityProvider#getName name} of the service provider, the
+ * {@link AccessibilityProvider#activate} method will be invoked to activate the
+ * matching service provider.
+ *
+ * @implSpec
+ * If assistive technology service providers are not specified with a system
+ * property this implementation will look in a properties file located as follows:
+ *
+ * This service provider class provides mappings from the platform
+ * specific accessibility APIs to the Java Accessibility API.
+ *
+ * Each service provider implementation is named and can be activated via the
+ * {@link #activate} method. Service providers can be loaded when the default
+ * {@link java.awt.Toolkit toolkit} is initialized.
+ *
+ * @apiNote There will typically be one provider per platform, such as Windows
+ * or Linux, to support accessibility for screen readers and magnifiers. However,
+ * more than one service provider can be activated. For example, a test tool
+ * which provides visual results obtained by interrogating the Java Accessibility
+ * API can be activated along with the activation of the support for screen readers
+ * and screen magnifiers.
+ *
+ * @see java.awt.Toolkit#getDefaultToolkit
+ * @see java.util.ServiceLoader
+ * @since 1.9
+ */
+public abstract class AccessibilityProvider {
+
+ /**
+ * Initializes a new accessibility provider.
+ *
+ * @throws SecurityException
+ * If a security manager has been installed and it denies
+ * {@link RuntimePermission} {@code "accessibilityProvider"}
+ */
+ protected AccessibilityProvider() {
+ // Use a permission check when calling a private constructor to check that
+ // the proper security permission has been granted before the Object superclass
+ // is called. If an exception is thrown before the Object superclass is
+ // constructed a finalizer in a subclass of this class will not be run.
+ // This protects against a finalizer vulnerability.
+ this(checkPermission());
+ }
+
+ private AccessibilityProvider(Void ignore) { }
+
+ /**
+ * If this code is running with a security manager and if the permission
+ * "accessibilityProvider" has not been granted SecurityException will be thrown.
+ *
+ */
+ private static Void checkPermission() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission("accessibilityProvider"));
+ return null;
+ }
+
+ /**
+ * Returns the name of this service provider. This name is used to locate a
+ * requested service provider.
+ *
+ * @return the name of this service provider
+ */
+ public abstract String getName();
+
+ /**
+ * Activates the support provided by this service provider.
+ */
+ public abstract void activate();
+
+}
diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java
index 76451154127..f22fd8e86dd 100644
--- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java
+++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -896,11 +896,12 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI {
// Paint the background for the tab area
if ( tabPane.isOpaque() ) {
- if (!c.isBackgroundSet() && (tabAreaBackground != null)) {
+ Color background = c.getBackground();
+ if (background instanceof UIResource && tabAreaBackground != null) {
g.setColor(tabAreaBackground);
}
else {
- g.setColor( c.getBackground() );
+ g.setColor(background);
}
switch ( tabPlacement ) {
case LEFT:
diff --git a/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java b/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java
index 80b58f37e1c..847c0884b6a 100644
--- a/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java
+++ b/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java
@@ -291,7 +291,7 @@ public abstract class SunToolkit extends Toolkit
// Maps from non-Component/MenuComponent to AppContext.
// WeakHashMap {@code
+ * Stream
+ *
+ * @return a Stream of NetworkInterfaces found on this machine
+ * @exception SocketException if an I/O error occurs.
+ * @since 1.9
+ */
+ public static StreamGraphicsEnvironment.isHeadless returns true
* @exception AWTException in case of erroneous retrieving of the cursor
*/
- static public Cursor getSystemCustomCursor(final String name)
+ public static Cursor getSystemCustomCursor(final String name)
throws AWTException, HeadlessException {
GraphicsEnvironment.checkHeadless();
Cursor cursor = systemCustomCursors.get(name);
@@ -330,18 +330,15 @@ public class Cursor implements java.io.Serializable {
} catch (NumberFormatException nfe) {
throw new AWTException("failed to parse hotspot property for cursor: " + name);
}
-
- try {
- final Toolkit toolkit = Toolkit.getDefaultToolkit();
- final String file = RESOURCE_PREFIX + fileName;
-
- cursor = AccessController.doPrivileged(
- (PrivilegedExceptionActionClassLoader.getSystemClassLoader, whose
- * delegation parent is the extension class loader for installed
- * extensions).
+ * @param s the error message
+ * @param e the original exception
+ * @throw the new AWTError including the cause (the original exception)
+ */
+ private static void newAWTError(Throwable e, String s) {
+ AWTError newAWTError = new AWTError(s);
+ newAWTError.initCause(e);
+ throw newAWTError;
+ }
+
+ /**
+ * When a service provider for Assistive Technology is not found look for a
+ * supporting class on the class path and instantiate it.
+ *
+ * @param atName the name of the class to be loaded
+ */
+ private static void fallbackToLoadClassForAT(String atName) {
+ try {
+ Class.forName(atName, false, ClassLoader.getSystemClassLoader()).newInstance();
+ } catch (ClassNotFoundException e) {
+ newAWTError(e, "Assistive Technology not found: " + atName);
+ } catch (InstantiationException e) {
+ newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
+ } catch (IllegalAccessException e) {
+ newAWTError(e, "Could not access Assistive Technology: " + atName);
+ } catch (Exception e) {
+ newAWTError(e, "Error trying to install Assistive Technology: " + atName);
+ }
+ }
+
+ /**
+ * Loads accessibility support using the property assistive_technologies.
+ * The form is assistive_technologies= followed by a comma-separated list of
+ * assistive technology providers to load. The order in which providers are
+ * loaded is determined by the order in which the ServiceLoader discovers
+ * implementations of the AccessibilityProvider interface, not by the order
+ * of provider names in the property list. When a provider is found its
+ * accessibility implementation will be started by calling the provider's
+ * activate method. All errors are handled via an AWTError exception.
*/
private static void loadAssistiveTechnologies() {
// Load any assistive technologies
if (atNames != null) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
- StringTokenizer parser = new StringTokenizer(atNames," ,");
- String atName;
- while (parser.hasMoreTokens()) {
- atName = parser.nextToken();
+ Set"java.awt.headless" is set
- * to true then the headless implementation
- * of Toolkit is used.
+ * If a system property named {@code "java.awt.headless"} is set
+ * to {@code true} then the headless implementation
+ * of {@code Toolkit} is used.
* "java.awt.headless" or it is set to
- * false and there is a system property named
- * "awt.toolkit",
+ * If there is no {@code "java.awt.headless"} or it is set to
+ * {@code false} and there is a system property named
+ * {@code "awt.toolkit"},
* that property is treated as the name of a class that is a subclass
- * of Toolkit;
+ * of {@code Toolkit};
* otherwise the default platform-specific implementation of
- * Toolkit is used.
+ * {@code Toolkit} is used.
*
+ *
+ * Only the first of these files to be located will be consulted. The requested
+ * service providers are specified by setting the {@code assistive_technologies=}
+ * property. A single provider or a comma separated list of providers can be
+ * specified.
+ *
+ * @return the default toolkit.
* @exception AWTError if a toolkit could not be found, or
* if one could not be accessed or instantiated.
+ * @see java.util.ServiceLoader
+ * @see javax.accessibility.AccessibilityProvider
*/
public static synchronized Toolkit getDefaultToolkit() {
if (toolkit == null) {
@@ -550,7 +598,9 @@ public abstract class Toolkit {
return null;
}
});
- loadAssistiveTechnologies();
+ if (!GraphicsEnvironment.isHeadless()) {
+ loadAssistiveTechnologies();
+ }
}
return toolkit;
}
diff --git a/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibilityProvider.java b/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibilityProvider.java
new file mode 100644
index 00000000000..001b42f15d6
--- /dev/null
+++ b/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibilityProvider.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package javax.accessibility;
+
+/**
+ * Service Provider Interface (SPI) for Assistive Technology.
+ *