<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2009, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.marshalling.serialization.jboss;

import static org.jboss.marshalling.serialization.jboss.Protocol.ID_EXTERNALIZER_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_NEW_OBJECT;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_NO_CLASS_DESC;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_ORDINARY_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PREDEFINED_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PREDEFINED_OBJECT;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PROXY_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PROXY_OBJECT;

import java.io.IOException;
import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ClassTable;
import org.jboss.marshalling.Creator;
import org.jboss.marshalling.Externalizer;
import org.jboss.marshalling.ObjectResolver;
import org.jboss.marshalling.ObjectTable;
import org.jboss.marshalling.StreamHeader;
import org.jboss.marshalling.Unmarshaller;
import org.jboss.marshalling.serialization.java.ObjectResolverWrapper;
import org.jboss.serial.classmetamodel.ClassMetaData;
import org.jboss.serial.classmetamodel.ClassMetaDataSlot;
import org.jboss.serial.classmetamodel.DefaultClassDescriptorStrategy;
import org.jboss.serial.classmetamodel.StreamingClass;
import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
import org.jboss.serial.objectmetamodel.DefaultObjectDescriptorStrategy;
import org.jboss.serial.objectmetamodel.ObjectsCache;
import org.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationInputInterface;
import org.jboss.serial.util.HashStringUtil;
import org.jboss.serial.util.StringUtilBuffer;

/**
 * @author <a href="<EMAIL>"><NAME></a>
 * @version 
 * <p>
 * Copyright Jan 29, 2009
 * </p>
 */
public class JBossSerializationInputStream extends JBossObjectInputStreamSharedTree {
   
   private JBossSerializationUnmarshaller unmarshaller;
   private StreamHeader streamHeader;
   private ClassResolver classResolver;
   private ClassTable classTable;
   private ObjectResolver objectResolver;
   private ObjectTable objectTable;
   private Creator creator;
   private ThreadLocal<String> resolvedClassName = new ThreadLocal<String>();
   private ThreadLocal<Class<?>> resolvedClass = new ThreadLocal<Class<?>>();
   private boolean readyForStreamHeader;
   
   public JBossSerializationInputStream(JBossSerializationUnmarshaller unmarshaller,
                                        StreamHeader streamHeader,
                                        ClassResolver classResolver,
                                        ClassTable classTable,
                                        ObjectResolver objectResolver,
                                        ObjectTable objectTable,
                                        Creator creator) throws IOException {
      super(unmarshaller.getInputStream(), new StringUtilBuffer(10024, 10024));
      this.unmarshaller = unmarshaller;
      this.streamHeader = streamHeader;
      this.classResolver = classResolver;
      this.classTable = classTable;
      this.objectResolver = new ObjectResolverWrapper(objectResolver);
      this.objectTable = objectTable;
      this.creator = creator;
      
      AccessController.doPrivileged(new PrivilegedAction<Void>() {
         public Void run() {
            enableResolveObject(true);
            return null;
         }
      });
      
      setClassDescriptorStrategy(new JBMClassDescriptorStrategy(unmarshaller, this, classTable, classResolver));
      setObjectDescriptorStrategy(new JBMObjectDescriptorStrategy(unmarshaller, this));
      setStandardReplacement(true);
      readyForStreamHeader = true;
   }
   
   public void clear() {
   }
   
   public Creator getCreator() {
      return creator;
   }
   
   public ObjectTable getObjectTable() {
      return objectTable;
   }<commit_msg>JBMAR-33: Added jbossSerializationCompatible flag to allow compatibility with JBossObjectInputStream.<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2009, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.marshalling.serialization.jboss;

import static org.jboss.marshalling.serialization.jboss.Protocol.ID_EXTERNALIZER_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_NEW_OBJECT;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_NO_CLASS_DESC;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_ORDINARY_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PREDEFINED_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PREDEFINED_OBJECT;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PROXY_CLASS;
import static org.jboss.marshalling.serialization.jboss.Protocol.ID_PROXY_OBJECT;

import java.io.IOException;
import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.jboss.marshalling.ClassResolver;
import org.jboss.marshalling.ClassTable;
import org.jboss.marshalling.Creator;
import org.jboss.marshalling.Externalizer;
import org.jboss.marshalling.ObjectResolver;
import org.jboss.marshalling.ObjectTable;
import org.jboss.marshalling.StreamHeader;
import org.jboss.marshalling.Unmarshaller;
import org.jboss.marshalling.serialization.java.ObjectResolverWrapper;
import org.jboss.serial.classmetamodel.ClassMetaData;
import org.jboss.serial.classmetamodel.ClassMetaDataSlot;
import org.jboss.serial.classmetamodel.DefaultClassDescriptorStrategy;
import org.jboss.serial.classmetamodel.StreamingClass;
import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
import org.jboss.serial.objectmetamodel.DefaultObjectDescriptorStrategy;
import org.jboss.serial.objectmetamodel.ObjectsCache;
import org.jboss.serial.objectmetamodel.ObjectsCache.JBossSeralizationInputInterface;
import org.jboss.serial.util.HashStringUtil;
import org.jboss.serial.util.StringUtilBuffer;

/**
 * @author <a href="ron.sigal<EMAIL>"><NAME></a>
 * @version 
 * <p>
 * Copyright Jan 29, 2009
 * </p>
 */
public class JBossSerializationInputStream extends JBossObjectInputStreamSharedTree {
   
   private JBossSerializationUnmarshaller unmarshaller;
   private StreamHeader streamHeader;
   private ClassResolver classResolver;
   private ClassTable classTable;
   private ObjectResolver objectResolver;
   private ObjectTable objectTable;
   private Creator creator;
   private ThreadLocal<String> resolvedClassName = new ThreadLocal<String>();
   private ThreadLocal<Class<?>> resolvedClass = new ThreadLocal<Class<?>>();
   private boolean readyForStreamHeader;
   
   public JBossSerializationInputStream(JBossSerializationUnmarshaller unmarshaller,
                                        StreamHeader streamHeader,
                                        ClassResolver classResolver,
                                        ClassTable classTable,
                                        ObjectResolver objectResolver,
                                        ObjectTable objectTable,
                                        Creator creator, 
                                        boolean jbossSerializationCompatible) throws IOException {
      super(unmarshaller.getInputStream(), new StringUtilBuffer(10024, 10024));
      this.unmarshaller = unmarshaller;
      this.streamHeader = streamHeader;
      this.classResolver = classResolver;
      this.classTable = classTable;
      this.objectResolver = new ObjectResolverWrapper(objectResolver);
      this.objectTable = objectTable;
      this.creator = creator;
      
      AccessController.doPrivileged(new PrivilegedAction<Void>() {
         public Void run() {
            enableResolveObject(true);
            return null;
         }
      });
      
      if (jbossSerializationCompatible) {
         setClassDescriptorStrategy(new DefaultClassDescriptorStrategy());
         setObjectDescriptorStrategy(new DefaultObjectDescriptorStrategy());
         setStandardReplacement(false);
      } else {
         setClassDescriptorStrategy(new JBMClassDescriptorStrategy(unmarshaller, this, classTable, classResolver));
         setObjectDescriptorStrategy(new JBMObjectDescriptorStrategy(unmarshaller, this));
         setStandardReplacement(true);
      }
      
      readyForStreamHeader = true;
   }
   
   public void clear() {
   }
   
   public Creator getCreator() {
      return creator;
   }
   
   public ObjectTable getObjectTable() {
      return objectTable;
   }
{'fraction_non_alphanumeric': 0.07369875633348687, 'fraction_numerical': 0.0062643942883463845, 'mean_word_length': 3.8120567375886525, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116099', 'n_tokens_mistral': 2972, 'n_tokens_neox': 2859, 'n_words': 718}