feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,173 @@
/*
* Copyright (c) 2000, 2013, 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 sun.awt.datatransfer;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Reads all of the data from the system Clipboard which the data transfer
* subsystem knows how to translate. This includes all text data, File Lists,
* Serializable objects, Remote objects, and properly registered, arbitrary
* data as InputStreams. The data is stored in byte format until requested
* by client code. At that point, the data is converted, if necessary, into
* the proper format to deliver to the application.
*
* This hybrid pre-fetch/delayed-rendering approach allows us to circumvent
* the API restriction that client code cannot lock the Clipboard to discover
* its formats before requesting data in a particular format, while avoiding
* the overhead of fully rendering all data ahead of time.
*
* @author David Mendenhall
* @author Danila Sinopalnikov
*
* @since 1.4 (appeared in modified form as FullyRenderedTransferable in 1.3.1)
*/
public class ClipboardTransferable implements Transferable {
private final HashMap flavorsToData = new HashMap();
private DataFlavor[] flavors = new DataFlavor[0];
private final class DataFactory {
final long format;
final byte[] data;
DataFactory(long format, byte[] data) {
this.format = format;
this.data = data;
}
public Object getTransferData(DataFlavor flavor) throws IOException {
return DataTransferer.getInstance().
translateBytes(data, flavor, format,
ClipboardTransferable.this);
}
}
public ClipboardTransferable(SunClipboard clipboard) {
clipboard.openClipboard(null);
try {
long[] formats = clipboard.getClipboardFormats();
if (formats != null && formats.length > 0) {
// Since the SystemFlavorMap will specify many DataFlavors
// which map to the same format, we should cache data as we
// read it.
HashMap cached_data = new HashMap(formats.length, 1.0f);
Map flavorsForFormats = DataTransferer.getInstance().
getFlavorsForFormats(formats, SunClipboard.getDefaultFlavorTable());
for (Iterator iter = flavorsForFormats.keySet().iterator();
iter.hasNext(); )
{
DataFlavor flavor = (DataFlavor)iter.next();
Long lFormat = (Long)flavorsForFormats.get(flavor);
fetchOneFlavor(clipboard, flavor, lFormat, cached_data);
}
flavors = DataTransferer.getInstance().
setToSortedDataFlavorArray(flavorsToData.keySet());
}
} finally {
clipboard.closeClipboard();
}
}
private boolean fetchOneFlavor(SunClipboard clipboard, DataFlavor flavor,
Long lFormat, HashMap cached_data)
{
if (!flavorsToData.containsKey(flavor)) {
long format = lFormat.longValue();
Object data = null;
if (!cached_data.containsKey(lFormat)) {
try {
data = clipboard.getClipboardData(format);
} catch (IOException e) {
data = e;
} catch (Throwable e) {
e.printStackTrace();
}
// Cache this data, even if it's null, so we don't have to go
// to native code again for this format.
cached_data.put(lFormat, data);
} else {
data = cached_data.get(lFormat);
}
// Casting IOException to byte array causes ClassCastException.
// We should handle IOException separately - do not wrap them into
// DataFactory and report failure.
if (data instanceof IOException) {
flavorsToData.put(flavor, data);
return false;
} else if (data != null) {
flavorsToData.put(flavor, new DataFactory(format,
(byte[])data));
return true;
}
}
return false;
}
public DataFlavor[] getTransferDataFlavors() {
return (DataFlavor[])flavors.clone();
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavorsToData.containsKey(flavor);
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException
{
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
Object ret = flavorsToData.get(flavor);
if (ret instanceof IOException) {
// rethrow IOExceptions generated while fetching data
throw (IOException)ret;
} else if (ret instanceof DataFactory) {
// Now we can render the data
DataFactory factory = (DataFactory)ret;
ret = factory.getTransferData(flavor);
}
return ret;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,468 @@
/*
* Copyright (c) 1999, 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 sun.awt.datatransfer;
import java.awt.EventQueue;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.FlavorTable;
import java.awt.datatransfer.SystemFlavorMap;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorListener;
import java.awt.datatransfer.FlavorEvent;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import java.io.IOException;
import sun.awt.AppContext;
import sun.awt.PeerEvent;
import sun.awt.SunToolkit;
import sun.awt.EventListenerAggregate;
/**
* Serves as a common, helper superclass for the Win32 and X11 system
* Clipboards.
*
* @author Danila Sinopalnikov
* @author Alexander Gerasimov
*
* @since 1.3
*/
public abstract class SunClipboard extends Clipboard
implements PropertyChangeListener {
private AppContext contentsContext = null;
private final Object CLIPBOARD_FLAVOR_LISTENER_KEY;
/**
* A number of <code>FlavorListener</code>s currently registered
* on this clipboard across all <code>AppContext</code>s.
*/
private volatile int numberOfFlavorListeners = 0;
/**
* A set of {@code DataFlavor}s that is available on this clipboard. It is
* used for tracking changes of {@code DataFlavor}s available on this
* clipboard. Can be {@code null}.
*/
private volatile long[] currentFormats;
public SunClipboard(String name) {
super(name);
CLIPBOARD_FLAVOR_LISTENER_KEY = new StringBuffer(name + "_CLIPBOARD_FLAVOR_LISTENER_KEY");
}
public synchronized void setContents(Transferable contents,
ClipboardOwner owner) {
// 4378007 : Toolkit.getSystemClipboard().setContents(null, null)
// should throw NPE
if (contents == null) {
throw new NullPointerException("contents");
}
initContext();
final ClipboardOwner oldOwner = this.owner;
final Transferable oldContents = this.contents;
try {
this.owner = owner;
this.contents = new TransferableProxy(contents, true);
setContentsNative(contents);
} finally {
if (oldOwner != null && oldOwner != owner) {
EventQueue.invokeLater(new Runnable() {
public void run() {
oldOwner.lostOwnership(SunClipboard.this, oldContents);
}
});
}
}
}
private synchronized void initContext() {
final AppContext context = AppContext.getAppContext();
if (contentsContext != context) {
// Need to synchronize on the AppContext to guarantee that it cannot
// be disposed after the check, but before the listener is added.
synchronized (context) {
if (context.isDisposed()) {
throw new IllegalStateException("Can't set contents from disposed AppContext");
}
context.addPropertyChangeListener
(AppContext.DISPOSED_PROPERTY_NAME, this);
}
if (contentsContext != null) {
contentsContext.removePropertyChangeListener
(AppContext.DISPOSED_PROPERTY_NAME, this);
}
contentsContext = context;
}
}
public synchronized Transferable getContents(Object requestor) {
if (contents != null) {
return contents;
}
return new ClipboardTransferable(this);
}
/**
* @return the contents of this clipboard if it has been set from the same
* AppContext as it is currently retrieved or null otherwise
* @since 1.5
*/
protected synchronized Transferable getContextContents() {
AppContext context = AppContext.getAppContext();
return (context == contentsContext) ? contents : null;
}
/**
* @see java.awt.Clipboard#getAvailableDataFlavors
* @since 1.5
*/
public DataFlavor[] getAvailableDataFlavors() {
Transferable cntnts = getContextContents();
if (cntnts != null) {
return cntnts.getTransferDataFlavors();
}
long[] formats = getClipboardFormatsOpenClose();
return DataTransferer.getInstance().
getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
}
/**
* @see java.awt.Clipboard#isDataFlavorAvailable
* @since 1.5
*/
public boolean isDataFlavorAvailable(DataFlavor flavor) {
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContextContents();
if (cntnts != null) {
return cntnts.isDataFlavorSupported(flavor);
}
long[] formats = getClipboardFormatsOpenClose();
return formatArrayAsDataFlavorSet(formats).contains(flavor);
}
/**
* @see java.awt.Clipboard#getData
* @since 1.5
*/
public Object getData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContextContents();
if (cntnts != null) {
return cntnts.getTransferData(flavor);
}
long format = 0;
byte[] data = null;
Transferable localeTransferable = null;
try {
openClipboard(null);
long[] formats = getClipboardFormats();
Long lFormat = (Long)DataTransferer.getInstance().
getFlavorsForFormats(formats, getDefaultFlavorTable()).get(flavor);
if (lFormat == null) {
throw new UnsupportedFlavorException(flavor);
}
format = lFormat.longValue();
data = getClipboardData(format);
if (DataTransferer.getInstance().isLocaleDependentTextFormat(format)) {
localeTransferable = createLocaleTransferable(formats);
}
} finally {
closeClipboard();
}
return DataTransferer.getInstance().
translateBytes(data, flavor, format, localeTransferable);
}
/**
* The clipboard must be opened.
*
* @since 1.5
*/
protected Transferable createLocaleTransferable(long[] formats) throws IOException {
return null;
}
/**
* @throws IllegalStateException if the clipboard has not been opened
*/
public void openClipboard(SunClipboard newOwner) {}
public void closeClipboard() {}
public abstract long getID();
public void propertyChange(PropertyChangeEvent evt) {
if (AppContext.DISPOSED_PROPERTY_NAME.equals(evt.getPropertyName()) &&
Boolean.TRUE.equals(evt.getNewValue())) {
final AppContext disposedContext = (AppContext)evt.getSource();
lostOwnershipLater(disposedContext);
}
}
protected void lostOwnershipImpl() {
lostOwnershipLater(null);
}
/**
* Clears the clipboard state (contents, owner and contents context) and
* notifies the current owner that ownership is lost. Does nothing if the
* argument is not <code>null</code> and is not equal to the current
* contents context.
*
* @param disposedContext the AppContext that is disposed or
* <code>null</code> if the ownership is lost because another
* application acquired ownership.
*/
protected void lostOwnershipLater(final AppContext disposedContext) {
final AppContext context = this.contentsContext;
if (context == null) {
return;
}
SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
PeerEvent.PRIORITY_EVENT));
}
protected void lostOwnershipNow(final AppContext disposedContext) {
final SunClipboard sunClipboard = SunClipboard.this;
ClipboardOwner owner = null;
Transferable contents = null;
synchronized (sunClipboard) {
final AppContext context = sunClipboard.contentsContext;
if (context == null) {
return;
}
if (disposedContext == null || context == disposedContext) {
owner = sunClipboard.owner;
contents = sunClipboard.contents;
sunClipboard.contentsContext = null;
sunClipboard.owner = null;
sunClipboard.contents = null;
sunClipboard.clearNativeContext();
context.removePropertyChangeListener
(AppContext.DISPOSED_PROPERTY_NAME, sunClipboard);
} else {
return;
}
}
if (owner != null) {
owner.lostOwnership(sunClipboard, contents);
}
}
protected abstract void clearNativeContext();
protected abstract void setContentsNative(Transferable contents);
/**
* @since 1.5
*/
protected long[] getClipboardFormatsOpenClose() {
try {
openClipboard(null);
return getClipboardFormats();
} finally {
closeClipboard();
}
}
/**
* Returns zero-length array (not null) if the number of available formats is zero.
*
* @throws IllegalStateException if formats could not be retrieved
*/
protected abstract long[] getClipboardFormats();
protected abstract byte[] getClipboardData(long format) throws IOException;
private static Set formatArrayAsDataFlavorSet(long[] formats) {
return (formats == null) ? null :
DataTransferer.getInstance().
getFlavorsForFormatsAsSet(formats, getDefaultFlavorTable());
}
public synchronized void addFlavorListener(FlavorListener listener) {
if (listener == null) {
return;
}
AppContext appContext = AppContext.getAppContext();
EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
if (contextFlavorListeners == null) {
contextFlavorListeners = new EventListenerAggregate(FlavorListener.class);
appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, contextFlavorListeners);
}
contextFlavorListeners.add(listener);
if (numberOfFlavorListeners++ == 0) {
long[] currentFormats = null;
try {
openClipboard(null);
currentFormats = getClipboardFormats();
} catch (final IllegalStateException ignored) {
} finally {
closeClipboard();
}
this.currentFormats = currentFormats;
registerClipboardViewerChecked();
}
}
public synchronized void removeFlavorListener(FlavorListener listener) {
if (listener == null) {
return;
}
AppContext appContext = AppContext.getAppContext();
EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
if (contextFlavorListeners == null){
//else we throw NullPointerException, but it is forbidden
return;
}
if (contextFlavorListeners.remove(listener) &&
--numberOfFlavorListeners == 0) {
unregisterClipboardViewerChecked();
currentFormats = null;
}
}
public synchronized FlavorListener[] getFlavorListeners() {
EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
return contextFlavorListeners == null ? new FlavorListener[0] :
(FlavorListener[])contextFlavorListeners.getListenersCopy();
}
public boolean areFlavorListenersRegistered() {
return (numberOfFlavorListeners > 0);
}
protected abstract void registerClipboardViewerChecked();
protected abstract void unregisterClipboardViewerChecked();
/**
* Checks change of the <code>DataFlavor</code>s and, if necessary,
* posts notifications on <code>FlavorEvent</code>s to the
* AppContexts' EDTs.
* The parameter <code>formats</code> is null iff we have just
* failed to get formats available on the clipboard.
*
* @param formats data formats that have just been retrieved from
* this clipboard
*/
protected final void checkChange(final long[] formats) {
if (Arrays.equals(formats, currentFormats)) {
// we've been able to successfully get available on the clipboard
// DataFlavors this and previous time and they are coincident;
// don't notify
return;
}
currentFormats = formats;
class SunFlavorChangeNotifier implements Runnable {
private final FlavorListener flavorListener;
SunFlavorChangeNotifier(FlavorListener flavorListener) {
this.flavorListener = flavorListener;
}
public void run() {
if (flavorListener != null) {
flavorListener.flavorsChanged(new FlavorEvent(SunClipboard.this));
}
}
};
for (Iterator it = AppContext.getAppContexts().iterator(); it.hasNext();) {
AppContext appContext = (AppContext)it.next();
if (appContext == null || appContext.isDisposed()) {
continue;
}
EventListenerAggregate flavorListeners = (EventListenerAggregate)
appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
if (flavorListeners != null) {
FlavorListener[] flavorListenerArray =
(FlavorListener[])flavorListeners.getListenersInternal();
for (int i = 0; i < flavorListenerArray.length; i++) {
SunToolkit.postEvent(appContext, new PeerEvent(this,
new SunFlavorChangeNotifier(flavorListenerArray[i]),
PeerEvent.PRIORITY_EVENT));
}
}
}
}
public static FlavorTable getDefaultFlavorTable() {
return (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2000, 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 sun.awt.datatransfer;
public interface ToolkitThreadBlockedHandler {
public void lock();
public void unlock();
public void enter();
public void exit();
}

View File

@@ -0,0 +1,218 @@
/*
* Copyright (c) 2000, 2013, 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 sun.awt.datatransfer;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Proxies for another Transferable so that Serializable objects are never
* returned directly by DnD or the Clipboard. Instead, a new instance of the
* object is returned.
*
* @author Lawrence P.G. Cable
* @author David Mendenhall
*
* @since 1.4
*/
public class TransferableProxy implements Transferable {
public TransferableProxy(Transferable t, boolean local) {
transferable = t;
isLocal = local;
}
public DataFlavor[] getTransferDataFlavors() {
return transferable.getTransferDataFlavors();
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return transferable.isDataFlavorSupported(flavor);
}
public Object getTransferData(DataFlavor df)
throws UnsupportedFlavorException, IOException
{
Object data = transferable.getTransferData(df);
// If the data is a Serializable object, then create a new instance
// before returning it. This insulates applications sharing DnD and
// Clipboard data from each other.
if (data != null && isLocal && df.isFlavorSerializedObjectType()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ClassLoaderObjectOutputStream oos =
new ClassLoaderObjectOutputStream(baos);
oos.writeObject(data);
ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
try {
ClassLoaderObjectInputStream ois =
new ClassLoaderObjectInputStream(bais,
oos.getClassLoaderMap());
data = ois.readObject();
} catch (ClassNotFoundException cnfe) {
throw (IOException)new IOException().initCause(cnfe);
}
}
return data;
}
protected final Transferable transferable;
protected final boolean isLocal;
}
final class ClassLoaderObjectOutputStream extends ObjectOutputStream {
private final Map<Set<String>, ClassLoader> map =
new HashMap<Set<String>, ClassLoader>();
ClassLoaderObjectOutputStream(OutputStream os) throws IOException {
super(os);
}
protected void annotateClass(final Class<?> cl) throws IOException {
ClassLoader classLoader =
(ClassLoader)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return cl.getClassLoader();
}
});
Set<String> s = new HashSet<String>(1);
s.add(cl.getName());
map.put(s, classLoader);
}
protected void annotateProxyClass(final Class<?> cl) throws IOException {
ClassLoader classLoader =
(ClassLoader)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return cl.getClassLoader();
}
});
Class[] interfaces = cl.getInterfaces();
Set<String> s = new HashSet<String>(interfaces.length);
for (int i = 0; i < interfaces.length; i++) {
s.add(interfaces[i].getName());
}
map.put(s, classLoader);
}
Map<Set<String>, ClassLoader> getClassLoaderMap() {
return new HashMap(map);
}
}
final class ClassLoaderObjectInputStream extends ObjectInputStream {
private final Map<Set<String>, ClassLoader> map;
ClassLoaderObjectInputStream(InputStream is,
Map<Set<String>, ClassLoader> map)
throws IOException {
super(is);
if (map == null) {
throw new NullPointerException("Null map");
}
this.map = map;
}
protected Class<?> resolveClass(ObjectStreamClass classDesc)
throws IOException, ClassNotFoundException {
String className = classDesc.getName();
Set<String> s = new HashSet<String>(1);
s.add(className);
ClassLoader classLoader = map.get(s);
if (classLoader != null) {
return Class.forName(className, false, classLoader);
} else {
return super.resolveClass(classDesc);
}
}
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException {
Set<String> s = new HashSet<String>(interfaces.length);
for (int i = 0; i < interfaces.length; i++) {
s.add(interfaces[i]);
}
ClassLoader classLoader = map.get(s);
if (classLoader == null) {
return super.resolveProxyClass(interfaces);
}
// The code below is mostly copied from the superclass.
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any
Class[] classObjs = new Class[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
Class cl = Class.forName(interfaces[i], false, classLoader);
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) {
throw new IllegalAccessError(
"conflicting non-public interface class loaders");
}
} else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
try {
return Proxy.getProxyClass(hasNonPublicInterface ?
nonPublicLoader : classLoader,
classObjs);
} catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
}