public synchronized void putObjectStreamClassKey(ObjectStreamClass desc, int key) { ClassLoaderContext classLoaderContext = getClassLoaderContext(true); classLoaderContext.putObjectStreamClass(desc, key); if (_logger.isLoggable(Level.FINEST)) logFinest("Adding new ObjectStreamClass to outgoing context [" + desc.getName() + "] with specified key " + key + ", context class loader key " + classLoaderContext.getClassLoaderCacheKey()); }
int code = _context.getRepetitiveObjectsCache().get(obj); code = _context.getAndIncrementRepetitiveObjectCounter(); _context.getRepetitiveObjectsCache().put(obj, code);
/** * Overrides the original implementation, tries to save sending class descriptor, first checks * if the class was already sent. If it does send only the class index otherwise send the class * descriptor also. * * @param desc class descriptor to write to the stream. * @throws IOException If an I/O error has occurred. */ @Override protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { int i = _context.getObjectStreamClassKey(desc); boolean newClass = false; if (i == 0 || !_optimize) { newClass = true; if (_optimize) { i = _nextClassId++; _context.putObjectStreamClassKey(desc, i);// classMap.put(desc, i); } else { i = -1; } } writeInt(i); // write class ID if (newClass) // new class { super.writeClassDescriptor(desc); } }
/** * First checks that this class wasn't written already, if it does do nothing. * * <p>Else invokes {@link RMIClassLoader#getClassAnnotation RMIClassLoader.getClassAnnotation} * with <code>cl</code> to get the appropriate class annotation string value (possibly * <code>null</code>) and then writes a class annotation string value (possibly * <code>null</code>) to be read by a corresponding <code>MarshalInputStream</code> * implementation. * * <p><code>MarshalOutputStream</code> implements this method to just write the annotation value * to this stream using {@link ObjectOutputStream#writeUnshared writeUnshared}. * * <p>A subclass can override this method to write the annotation to a different location. * * @param annotation the class annotation string value (possibly <code>null</code>) to write * @throws IOException if I/O exception occurs writing the annotation **/ @Override protected void writeAnnotation(Class cl) throws IOException { if (_context.containsAnnotation(cl)) return; _context.addAnnotation(cl); super.writeAnnotation(cl); }
/** * Creates a new <code>MarshalOutputStream</code> that writes marshalled data to the specified * underlying <code>OutputStream</code>. * * <p>This constructor passes <code>out</code> to the superclass constructor that has an * <code>OutputStream</code> parameter. * * <p><code>context</code> will be used as the return value of the created stream's {@link * #getObjectStreamContext getObjectStreamContext} method. * * @param out the output stream to write marshalled data to * @param context the collection of context information objects to be returned by this stream's * {@link #getObjectStreamContext getObjectStreamContext} method * @param optimize whether to activate the class description optimization during serialization. * @throws IOException if the superclass's constructor throws an <code>IOException</code> * @throws SecurityException if the superclass's constructor throws a <code>SecurityException</code> * @throws NullPointerException if <code>out</code> or <code>context</code> is * <code>null</code> **/ public MarshalOutputStream(OutputStream out, boolean optimize) throws IOException { super(out); _optimize = optimize; _context = new Context(); }
public void closeContext() { _context.close(); }
public void resetContext() { _context.reset(); }
public synchronized boolean containsAnnotation(Class<?> cl) { ClassLoaderContext classLoaderContext = getClassLoaderContext(false); if (classLoaderContext == null) return false; return classLoaderContext.containsAnnotation(cl); }
public synchronized int getObjectStreamClassKey(ObjectStreamClass desc) { ClassLoaderContext classLoaderContext = getClassLoaderContext(false); if (classLoaderContext == null) return 0; return classLoaderContext.getObjectStreamClassKey(desc); }
public synchronized void addAnnotation(Class<?> cl) { ClassLoaderContext classLoaderContext = getClassLoaderContext(true); classLoaderContext.addAnnotation(cl); if (_logger.isLoggable(Level.FINEST)) logFinest("Adding new annotation to outgoing context [" + cl.getName() + "], context class loader key " + classLoaderContext.getClassLoaderCacheKey()); }