Object file handling giving java.io.StreamCorruptedException

Hi All,
I am storing and retriving objects from a file. but when i write multiple objects then while reading objects from the file its giving
java.io.StreamCorruptedExceptionPlease advice. Here's the code
import java.io.*;
class Person implements Serializable{
     String name = null;
     int age = 0;
     public void setName(String name){
          this.name = name;
     public String getName(){
          return this.name;
     public void setAge(int age){
          this.age = age;
     public int getAge(){
          return this.age;
public class ObjectFileRead{
     public static void main(String args[]){
     try{     
     *     Writing the objects to the file
          FileOutputStream out = new FileOutputStream("Person.dat",true);
          ObjectOutputStream objOutStream = new ObjectOutputStream (out);
          for(int i=0;i<5;i++){
               Person p = new Person();
               p.setName("MyName:1"+i);
               p.setAge(10+i);
               //System.out.println(p.getName());
               //System.out.println(p.getAge());
               objOutStream.writeObject (p);
          objOutStream.flush();
          objOutStream.close();
     *     Reading the objects fromt the file;
          FileInputStream inStream = new FileInputStream ("Person.dat");
          ObjectInputStream objInStream = new ObjectInputStream (inStream);
          try{
               while(true){
                    Person p = (Person)objInStream.readObject();
                    System.out.println(p.getName());
                    System.out.println(p.getAge());
          }catch(EOFException e){
     }catch(Exception e){
          System.out.println(e);
}

The output of ObjectOutputStream starts with a header. Because you append to the file Person.dat you end up with multiple headers, but you only open one ObjectInputStream. One approach would be to create a new ObjectInputStream wrapping inStream after every 5 objects read. I suspect a better one (because it avoids the risk of ObjectInputStream doing read-ahead and buffering) is to replace the appending with reading the file and writing it out again followed by the new objects.

Similar Messages

  • Is File handling in Java Swing possible?

    Hi I need to know whether file handling in Java Swing is possible or not?

    cents wrote:
    Thanks for ur answer.....Actually I just wanted to know whether "Reading from a file" and "Writing to a file" in Java Swing is possible or not?
    Edited by: cents on Mar 16, 2010 9:35 AMWhat did google tell you? Did you see anything interesting in the API?

  • Best practice: tar file handling through java on Linux

    What would be the better way to handle large size tar files (size may be more 1 GB) on Linux using Java? One way would be by using linux "tar" command through Runtime.exec, another option is through Java zip classes?
    Btw, functionality I am doing is extract the large tar file, remove some files and tar it back to make a smaller size tar ball. I am not too sure if Java provides an api to remove individual files/directory from a zip file.

    A tar file is not a zip file.
    Java provides no classes that handle .tar files by default.
    It does provide classes to handle the gzip compression that's often applied to .tar files (resulting in .tar.gz or .tgz files).
    So you either search for a library that handles tar files in Java or invoke tar as an external process.

  • Java.io.StreamCorruptedException: InputStream does not contain a serialized object

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

  • Issue with POF serialization - Failure to deserialize an Invocable object: java.io.StreamCorruptedException

    Am running into following exception even after following all guidelines to implement POF. The main objective is to perform Distributed Bulk cache loading.
    Oracle Coherence GE 3.7.1.10 <Error> (thread=Invocation:InvocationService, member=1): Failure to deserialize an Invocable object: java.io.StreamCorruptedException: unknown user type: 1001
    java.io.StreamCorruptedException: unknown user type: 1001
      at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3312)
      at com.tangosol.io.pof.PofBufferReader.readObject(PofBufferReader.java:2604)
      at com.tangosol.io.pof.ConfigurablePofContext.deserialize(ConfigurablePofContext.java:371)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.Service.readObject(Service.CDB:1)
      at com.tangosol.coherence.component.net.Message.readObject(Message.CDB:1)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService$InvocationRequest.read(InvocationService.CDB:8)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.deserializeMessage(Grid.CDB:19)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:31)
      at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
      at java.lang.Thread.run(Thread.java:662)
    Following is the pof-config.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
                xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config/1.1/coherence-pof-config.xsd">
      <user-type-list>
        <include>coherence-pof-config.xml</include>
        <user-type>
          <type-id>1001</type-id>
          <class-name>com.westgroup.coherence.bermuda.loader.DistributedLoaderAgent</class-name>
          <serializer>
            <class-name>com.tangosol.io.pof.PofAnnotationSerializer</class-name>     
            <init-params>
              <init-param>
                <param-type>int</param-type>
                <param-value>{type-id}</param-value>
              </init-param>
              <init-param>
                <param-type>java.lang.Class</param-type>
                <param-value>{class}</param-value>
              </init-param>
              <init-param>
                <param-type>boolean</param-type>
                <param-value>true</param-value>
              </init-param>
            </init-params>
          </serializer>
        </user-type>
         <user-type>
          <type-id>1002</type-id>
          <class-name>com.westgroup.coherence.bermuda.profile.lpa.LPACacheProfile</class-name>
          <serializer>
            <class-name>com.tangosol.io.pof.PofAnnotationSerializer</class-name>     
            <init-params>
              <init-param>
                <param-type>int</param-type>
                <param-value>{type-id}</param-value>
              </init-param>
              <init-param>
                <param-type>java.lang.Class</param-type>
                <param-value>{class}</param-value>
              </init-param>
              <init-param>
                <param-type>boolean</param-type>
                <param-value>true</param-value>
              </init-param>
            </init-params>
          </serializer>
        </user-type>
         <user-type>
          <type-id>1003</type-id>
          <class-name>com.westgroup.coherence.bermuda.profile.lpa.Address</class-name>
          <serializer>
            <class-name>com.tangosol.io.pof.PofAnnotationSerializer</class-name>     
            <init-params>
              <init-param>
                <param-type>int</param-type>
                <param-value>{type-id}</param-value>
              </init-param>
              <init-param>
                <param-type>java.lang.Class</param-type>
                <param-value>{class}</param-value>
              </init-param>
              <init-param>
                <param-type>boolean</param-type>
                <param-value>true</param-value>
              </init-param>
            </init-params>
          </serializer>
        </user-type>
         <user-type>
          <type-id>1004</type-id>
          <class-name>com.westgroup.coherence.bermuda.profile.lpa.Discipline</class-name>
          <serializer>
            <class-name>com.tangosol.io.pof.PofAnnotationSerializer</class-name>     
            <init-params>
              <init-param>
                <param-type>int</param-type>
                <param-value>{type-id}</param-value>
              </init-param>
              <init-param>
                <param-type>java.lang.Class</param-type>
                <param-value>{class}</param-value>
              </init-param>
              <init-param>
                <param-type>boolean</param-type>
                <param-value>true</param-value>
              </init-param>
            </init-params>
          </serializer>
        </user-type>
         <user-type>
          <type-id>1005</type-id>
          <class-name>com.westgroup.coherence.bermuda.profile.lpa.Employment</class-name>
          <serializer>
            <class-name>com.tangosol.io.pof.PofAnnotationSerializer</class-name>     
            <init-params>
              <init-param>
                <param-type>int</param-type>
                <param-value>{type-id}</param-value>
              </init-param>
              <init-param>
                <param-type>java.lang.Class</param-type>
                <param-value>{class}</param-value>
              </init-param>
              <init-param>
                <param-type>boolean</param-type>
                <param-value>true</param-value>
              </init-param>
            </init-params>
          </serializer>
        </user-type>
      </user-type-list>
      <allow-interfaces>true</allow-interfaces>
      <allow-subclasses>true</allow-subclasses>
    </pof-config>
    cache-config.xml
    <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
      xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config http://xmlns.oracle.com/coherence/coherence-cache-config/1.1/coherence-cache-config.xsd">
       <defaults>
        <serializer>pof</serializer>
        </defaults>
      <caching-scheme-mapping>
      <cache-mapping>
      <cache-name>DistributedLPACache</cache-name>
      <scheme-name>LPANewCache</scheme-name>
      <init-params>
      <init-param>
      <param-name>back-size-limit</param-name>
      <param-value>250MB</param-value>
      </init-param>
      </init-params>
      </cache-mapping>
      </caching-scheme-mapping>
      <caching-schemes>
      <!-- Distributed caching scheme. -->
      <distributed-scheme>
      <scheme-name>LPANewCache</scheme-name>
      <service-name>HBaseLPACache</service-name>
      <serializer>
      <instance>
                 <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
                 <init-params>
                   <init-param>
                     <param-type>java.lang.String</param-type>
                     <param-value>pof-config.xml</param-value>
                   </init-param>
                 </init-params>
            </instance>
      </serializer>
      <backing-map-scheme>
      <read-write-backing-map-scheme>
      <internal-cache-scheme>
      <class-scheme>
      <class-name>com.tangosol.util.ObservableHashMap</class-name>
      </class-scheme>
      </internal-cache-scheme>
      <cachestore-scheme>
      <class-scheme>
      <class-name>com.westgroup.coherence.bermuda.profile.lpa.LPACacheProfile</class-name>
      </class-scheme>
      </cachestore-scheme>
      <read-only>false</read-only>
      <write-delay-seconds>0</write-delay-seconds>
      </read-write-backing-map-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
      </distributed-scheme>
      <invocation-scheme>
           <scheme-name>InvocationService</scheme-name>
           <service-name>InvocationService</service-name>
           <thread-count>5</thread-count>
           <autostart>true</autostart>
        </invocation-scheme>
      </caching-schemes>
    </cache-config>
    DistributedLoaderAgent (user type 1001)
    import java.io.IOException;
    import java.io.Serializable;
    import java.lang.annotation.Annotation;
    import org.apache.log4j.Logger;
    import com.tangosol.io.pof.PofReader;
    import com.tangosol.io.pof.PofWriter;
    import com.tangosol.io.pof.PortableObject;
    import com.tangosol.io.pof.annotation.Portable;
    import com.tangosol.io.pof.annotation.PortableProperty;
    import com.tangosol.net.AbstractInvocable;
    import com.tangosol.net.InvocationService;
    @Portable
    public class DistributedLoaderAgent extends AbstractInvocable implements PortableObject{
      private static final long serialVersionUID = 10L;
      private static Logger m_logger = Logger.getLogger(DistributedLoaderAgent.class);
      @PortableProperty(0)
      public String partDumpFileName = null;
      public String getPartDumpFileName() {
      return partDumpFileName;
      public void setPartDumpFileName(String partDumpFileName) {
      this.partDumpFileName = partDumpFileName;
      public DistributedLoaderAgent(){
      super();
      m_logger.debug("Configuring this loader ");
      public DistributedLoaderAgent(String partDumpFile){
      super();
      m_logger.debug("Configuring this loader to load dump file "+ partDumpFile);
      partDumpFileName = partDumpFile;
      @Override
      public void init(InvocationService service) {
      // TODO Auto-generated method stub
      super.init(service);
      @Override
      public void run() {
      // TODO Auto-generated method stub
      try{
      m_logger.debug("Invoked DistributedLoaderAgent");
      MetadataTranslatorService service = new MetadataTranslatorService(false, "LPA");
      m_logger.debug("Invoking service.loadLPACache");
      service.loadLPACache(partDumpFileName);
      }catch(Exception e){
      m_logger.debug("Exception in DistributedLoaderAgent " + e.getMessage());
      @Override
      public void readExternal(PofReader arg0) throws IOException {
      // TODO Auto-generated method stub
      setPartDumpFileName(arg0.readString(0));
      @Override
      public void writeExternal(PofWriter arg0) throws IOException {
      // TODO Auto-generated method stub
      arg0.writeString(0, getPartDumpFileName());
    Please assist.

    OK I have two suggestions.
    1. Always create and flush the ObjectOutputStream before creating the ObjectInputStream.
    2. Always close the output before you close the input. Actually once you close the output stream both the input stream and the socket are closed anyway so you can economize on this code. In the above you have out..writeObject() followed by input.close() followed by out.close(). Change this to out.writeObject() followed by out.close(). It may be that something needed flushing and the input.close() prevented the flush from happening.

  • Java.io.StreamCorruptedException: illegal handle value

    Hi
    I am using Oracle Coherence 3.3 in my application. I my application we are taking the objects from Webservices and storing them in the Cache(Replicated). And then retrieve them from the Cache.
    But now on our application Linux server we are getting "java.io.StreamCorruptedException: illegal handle value"
    Can anybody tell the reason of this. I am not sure whether it is a Coherence issue.
    The log of error which i am getting is this. Please do reply. Its really urgent.
    [6/7/08 11:23:36:287 EDT] 00004442 SystemErr R (Wrapped: CacheName=UMAChannelZipCache, Key=44120) java.io.StreamCorruptedException: illegal handle value
         at java.io.ObjectInputStream.readHandle(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
         at java.util.HashMap.readObject(HashMap.java(Compiled Code))
         at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
         at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java(Compiled Code))
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Compiled Code))
         at java.util.TreeMap.buildFromSorted(TreeMap.java(Inlined Compiled Code))
         at java.util.TreeMap.readTreeSet(TreeMap.java(Inlined Compiled Code))
         at java.util.TreeSet.readObject(TreeSet.java(Compiled Code))
         at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
         at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java(Compiled Code))
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
         at java.util.HashMap.readObject(HashMap.java(Compiled Code))
         at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
         at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java(Compiled Code))
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
         at com.tangosol.util.ExternalizableHelper.readSerializable(ExternalizableHelper.java(Inlined Compiled Code))
         at com.tangosol.util.ExternalizableHelper.readObject(ExternalizableHelper.java(Compiled Code))
         at com.tangosol.coherence.component.net.Message.readObject(Message.CDB(Inlined Compiled Code))
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.ReplicatedCache$ConverterFromInternal.convert(ReplicatedCache.CDB(Compiled Code))
         at com.tangosol.coherence.component.util.CacheHandler.getCachedResource(CacheHandler.CDB(Compiled Code))
         at com.tangosol.coherence.component.util.CacheHandler.get(CacheHandler.CDB(Compiled Code))
         at com.tangosol.coherence.component.util.SafeNamedCache.get(SafeNamedCache.CDB(Compiled Code))
         at com.att.uma.cache.ChannelCacheManager.checkCacheByZip(ChannelCacheManager.java(Compiled Code))
         at com.att.uma.channel.UMAChannelServices.getChannelsByZip(UMAChannelServices.java(Compiled Code))
         at com.att.uma.channel.RetrieveChannelLineup.performTask(RetrieveChannelLineup.java(Compiled Code))
         at com.att.uma.channel.RetrieveChannelLineup.doPost(RetrieveChannelLineup.java(Compiled Code))
         at com.att.uma.channel.RetrieveChannelLineup.doGet(RetrieveChannelLineup.java(Compiled Code))
         at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
         at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java(Compiled Code))
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
         at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java(Compiled Code))
         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
         at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

    Hi user628020,
    Since you are using standard Java serialization, the only two reasons I can think of are:
    1) a bug in serialization routines for any of the classes your objects use (e.g. TreeMap)
    2) concurrent modification of the same object by another thread at the same time
    With urgent support questions I would suggest using the Oracle Metalink.
    Regards,
    Gene

  • Maximum file size handled by java

    Hi
    What is the maximum file size that java can handle i.e if I need to read a disk file using java, is there any limit on the size of the file being read?

    The size you can handle is not limited... only by your code :-)
    Check MemoryMappedFiles... i handle Gigabyte files with no problem ;-)

  • How to handle the java.policy file ?

    Can somebody tell me how to handle the java.policy file?
    I always get java.net.SocketExceptions and java.security.AccessControlExceptions while connecting to an appserver from an applet.
    What do I have to write in the java.policy file, where do I have to place it and do I have to call it in some way form my applet?
    Thanks in advance.
    don call

    The java.policy file goes in your jre installation directory in .../jre/lib/security (there should be one there already).
    I used it to allow otherwise restricted permissions for an applet using javax.comm. Add something like the following to the file:
    grant codeBase "URL:http://yourDomainName/rootDirectoryOfYourApp/*" {
         permission java.security.AllPermission;
    This will give the applet downloaded from your site all permissions. You might want to give only certain permissions, I don't know.
    Teri

  • Java - object file access

    how can I access randon to java object file
    thanks

    Can you clarify this question?
    I'm going to give an initial answer, based on a guess as to what you meant:
    BCEL lets you access the internals of a compiled Java class file (aka, the bytecode, aka the object code).

  • Java.io.EOFException in Object file transfer

    Greetings,
    I am having a problem sending a file across a network. At one point it was working, however I am not sure where along the way it became broken.
    Stack Trace:
    java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Sour
    ce)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at WBServer.unpackVectors(WBServer.java:283)
    at fileListener.run(WBServer.java:374)
        public void getWBContent(String hid) throws java.rmi.RemoteException //<- Send all object vectors and relevant integers...
            setPageNum(pageCount-1);
            HID=hid;
            packVectors(null);
            new Thread() {
                public void run(){
                   try{javax.swing.SwingUtilities.invokeLater(
                   new Runnable(){
                       public void run(){
                            try{ //Yes...
                                java.net.Socket s = new java.net.Socket(HID, 1113); //<- Make a network port
                                java.io.BufferedWriter sos = new java.io.BufferedWriter(new java.io.OutputStreamWriter(s.getOutputStream())); //<-Open a stream
                                sos.write("vectordata.dat"); //<-Send the name of the file
                                sos.close(); //<- Close the stream
                                s.close(); //<- Close the port
                                String anchor = getClass().getResource("WBServer.class").getPath();
                                java.net.Socket ns = new java.net.Socket(HID, 1113); //<- Open a new port to the same place
                                java.io.FileInputStream fio = new java.io.FileInputStream(anchor.substring(0, anchor.lastIndexOf('/')+1)+"vectordata.dat"); //<- Open the file to stream
                                //java.io.DataInputStream dia = new java.io.DataInputStream(fio); //<- Open the stream to read
                                java.io.BufferedInputStream bia = new java.io.BufferedInputStream(fio);
                                java.io.BufferedOutputStream boa = new java.io.BufferedOutputStream(ns.getOutputStream());//<- Open the data stream for the port
                                int read=0; //<- Byte Read Counter
                                byte[] fbuffer = new byte[1024]; //<- Byte Read Buffer
                                boolean EOF=false;
                                while(!EOF){ //<- Until we reach the end of the stream...
                                    try{read=bia.read(fbuffer);
                                    boa.write(fbuffer, 0, read);} //<- ...send the number of bytes stored in the buffer at the time.
                                    catch(java.io.EOFException e){ EOF=true;}
                                boa.flush(); //<- Make sure the stream is cleared
                                boa.close(); //<- Close the port's stream
                                bia.close(); //<- Close the reading stream
                                fio.close(); //<- Close the file's stream
                                ns.close(); //<- Close the port...
                            catch(Exception e)
                            {SimpleFormatter sf = new SimpleFormatter();
                             LogRecord tempLog = new LogRecord(Level.WARNING, "File Send Error: "+e.toString());
                             sf.format(tempLog);
                             logFile.publish(tempLog);}
                    catch(Exception e)
                    {SimpleFormatter sf = new SimpleFormatter();
                     LogRecord tempLog = new LogRecord(Level.WARNING, "Error running getWBContent() send file thread: "+e.toString());
                     sf.format(tempLog);
                     logFile.publish(tempLog);}
                }}.start();
        public void packVectors(String filePath) {   //This function writes all the objects in memory to a file for transport.
            String anchor = getClass().getResource("WBServer.class").getPath();
            if(filePath==null){filePath=anchor.substring(0, anchor.lastIndexOf('/')+1)+"data/vectordata.dat";}
            System.out.println("From packVectors(): "+filePath);
            java.io.File ovFile = new java.io.File(filePath); //Setup out data file
            try{if(!ovFile.exists()){ovFile.createNewFile();}else{ovFile.delete(); ovFile.createNewFile();} //If it's not there...make one. If it is, delete it and make a new one.
            java.io.ObjectOutputStream oojStream = new java.io.ObjectOutputStream(new java.io.FileOutputStream(ovFile)); //Ready the writer for writingness.
            oojStream.writeObject(PageHolder); //Pages to file...
            oojStream.writeObject(ImgPage); //Images for the Pages to file...
            oojStream.writeObject(WBStack); //Current object stack to file...
            oojStream.writeInt(objCount); //Current object count to file...
            oojStream.writeInt(pageCount); //Current page count to file...
            oojStream.writeInt(pageCount-1); //Current page number to file...
            oojStream.flush(); //<-Commit final write operations...
            oojStream.close();} //<- Close the file...
            catch(Exception e)
            {SimpleFormatter s = new SimpleFormatter();
             LogRecord tempLog = new LogRecord(Level.WARNING, "Persistence save error: "+e.toString());
             s.format(tempLog);
             e.printStackTrace();
             logFile.publish(tempLog);}
        public void unpackVectors(String filePath) {   //This function reads objects from a file that was previously written by packVectors().
            String anchor = getClass().getResource("WBServer.class").getPath();
            if(filePath==null){filePath=anchor.substring(0, anchor.lastIndexOf('/')+1)+"data/vectordata.dat";}
            System.out.println("From unpackVectors(): "+filePath);
            java.io.File ivFile = new java.io.File(filePath); //Setup the file to read from.
            try{if(!ivFile.exists()){ //If the file doesn't exist, we're screwed...
                SimpleFormatter s = new SimpleFormatter();
                LogRecord tempLog = new LogRecord(Level.WARNING, "Persistence load error: File vectordata.dat does not exist!");
                s.format(tempLog);
                logFile.publish(tempLog);
            }else{
                java.io.ObjectInputStream iojStream = new java.io.ObjectInputStream(new java.io.FileInputStream(ivFile)); //Ready the reader for readingness...
                PageHolder = (java.util.Vector)iojStream.readObject(); //Pages from file...
                ImgPage = (java.util.Vector)iojStream.readObject(); //images for Pages from file...
                WBStack = (java.util.Vector)iojStream.readObject(); //Current object stack from file...
                objCount = iojStream.readInt(); //Current object count from file...
                pageCount = iojStream.readInt(); //Current number of pages from file...
                pageNum = iojStream.readInt();//iojStream.readInt(); //Current page number from file...
                iojStream.close();}} //Close the file...
            catch(Exception e)// We screwed up somewhere.....
            {SimpleFormatter s = new SimpleFormatter();
             LogRecord tempLog = new LogRecord(Level.WARNING, "Persistence load error: "+e.toString());
             s.format(tempLog);
             e.printStackTrace();
             logFile.publish(tempLog);}
    class fileListener extends Thread {
        public fileListener(WBServer wb) //<-Constructor
            try{ms = new java.net.ServerSocket(1113);} //<- Listener socket
            catch(Exception e){e.toString();}
            server = wb; //<- Referencial variable back to the server
        public fileListener(WBServer wb, int port) //<- Constructor with port
            try{ms = new java.net.ServerSocket(port);} //<- Listener socket
            catch(Exception e){e.toString();}
            server = wb; //<- Referencial variable back to the server
        public void run() {
            String filepath; //<- Holder for file path operations...
            while(!disconnect) {
                try{java.net.Socket cs = ms.accept(); //<- Accept incoming request.
                server.fileStat = 1;
                java.io.BufferedReader str = new java.io.BufferedReader(new java.io.InputStreamReader(cs.getInputStream())); //<- Open communications with client
                String checkStr = str.readLine(); //<- Grab the file name from the client
                System.out.println(checkStr);
                String anchor = getClass().getResource("fileListener.class").getPath();
                if(checkStr.equalsIgnoreCase("vectordata.dat"))
                {filepath=anchor.substring(0, anchor.lastIndexOf('/')+1)+"data/"+checkStr;}
                else{filepath=anchor.substring(0, anchor.lastIndexOf('/')+1)+"scans/"+checkStr;}
                System.out.println(filepath);
                str.close(); //<- Close communications with client
                cs.close(); //<- Close socket
                //System.out.println("Recieved File Name: "+filepath);//Debugging
                java.io.File inFile = new java.io.File(filepath); //<- Make a file in memory on the host computer with the specified name.
                inFile.createNewFile(); //<- Create an empty file of that name within the local file system
                java.net.Socket ds = ms.accept(); //<- Accept incoming request
                java.io.FileOutputStream fos = new java.io.FileOutputStream(inFile); //<- Open file stream for writing...
                java.io.BufferedInputStream bis = new java.io.BufferedInputStream(ds.getInputStream()); //<- Open communications with client for data/
                byte[] fbuffer = new byte[1024]; //<- Byte read buffer
                int read=0; //<- Byte read counter
                server.fileStat = 2;
                while((read=bis.read(fbuffer))!=-1){ //<-Until we reach the end of the stream...
                    fos.write(fbuffer, 0, read); System.out.print(read+":");}// <- ...write the buffer to the file.
                fos.flush(); //<- Clear the file stream
                fos.close(); //<- Close the file stream
                bis.close(); //<- Close the data stream from the client
                if(checkStr.equalsIgnoreCase("vectordata.dat"))
                {server.fileStat = 3; // ...otherwise, we show loading...
                 server.unpackVectors(null);
                 server.sendRefresh(true);
                 server.fileStat=0;}
                else //If it's the sych data, unpack it and load the data
                {server.fileStat = 3; // ...otherwise, we show loading...
                 server.passImage(inFile); //<-Load the file into the image vector...
                 server.sendRefresh(true); //<- Ensure that the client updates properly
                 server.fileStat=0;}
                ds.close(); //<- Close the client socket
                catch(Exception e){e.toString();}
            //System.out.println("Listener Shutdown");//Debugging
            try{ms.close();} catch(Exception e){e.toString();} //<- Close the listening socket
        public boolean disconnect = false; //<- Flag for killing the "file server" prematurely
        private static WBServer server; //<- Referencial variable to the whiteboard server
        private java.net.ServerSocket ms; //<- Listener socket
    }I'm stumped as to where it is going wrong. I know that packVectors() and unpackVectors() both work, as they are used in a local save function. I suspect the problem lies between the getWBContent(String hid) and the fileListener class, but I am not certain where. Any help would be appreciated.

    First, you are expecting read(buffer,offset,count) to throw an EOFException. It doesn't, it returns -1 at EOF.
    Second, you are using a Writer to write binary data (resulting from serialization). This will corrupt it. Use an OutputStream.
    Third, what I really don't get is why would you (i) write local data to a file and (ii) start a new thread to (iii) read it back and (iv) send it over not one but two sockets, when you could just return the data as the result of the remote method without the file, the thread, or the Sockets.
    And in any case this sort of thing is most definitely not what SwingtUtilites.invokeLater() is for. (What it is for is updating Swing components and ensuring it all happens in the Swing thread, being the only correct way to write Swing code as Swing is not thread-safe by design.) If your server has a Swing GUI, which doesn't seem likely, it will stall for the duration of all this I/O. If it doesn't, why start the Swing thread at all?
    Just define a serializable object that contains all the data you are passing to writeObject()/writeInt() and return it as the result of the remote method.
    You will save yourself a lot of latency and code in the process, and you could reduce all this to about six lines of code, something like:
    return new WBContent(
    PageHolder, //Pages to file...
    ImgPage, //Images for the Pages to file...
    WBStack, //Current object stack to file...
    objCount, //Current object count to file...
    pageCount, //Current page count to file...
    pageCount-1 //Current page number to file...
    ); where WBContent is a serializable class with the appropriate members and constructor, and is the return type of getWBContent().

  • M new to this forum + new to java please help me with file handling program

    hi i want to make a file handling program where in i want to input a text file say f1 whose style is mentioned as below
    aaa...bcd
    aaabbc
    acdce
    a..dd
    abbcd
    now i want to write d out put of file f1 to file f2 but only those string entries widout any ... in them how to do that :-(( please help :((

    import java.io.*;
    import java.lang.*;
    class javcsse{
             void javsce (){
              BufferedReader in;
            PrintWriter out;
            String line;
            try
                in = new BufferedReader(new FileReader("e:\\cntcs\\n7.txt"));
                out = new PrintWriter("e:\\cntcs\\n8.txt");
               line = in.readLine();
               while(line != null)
                     if(line.contains("...") && line.contains("....")){
                         break ;                
                         else{
                               if(line.contains("cc"))
                              System.out.println(line+"\n");
                                      out.println(line);
                    line = in.readLine();
                in.close();
                out.close();
            } catch (Exception ex)
                System.err.println(ex.getMessage());
      public class javcse{
        public static void main(String[] args) {
            new javcsse();
    }hey i wrote this code yet could u tell y is it still not working :((

  • Java File Handling

    Hi Genious,
    I m maintaining a error log file in my java application.now i want as soon log file exceed size limit 1024 kb. a new file should be created in same folder with datetime stamp.
    pls give any me any idea how to achieve same ASAP.

    long fileSize = currentLogFile.length();
    // bytes to kb - 1048576 = 1024 * 1024
    if (filesize >= 1048576)
    To continue to log, depending on your code...you would probably need to close your streams from the old file, close the file, then create a new file with the new stamp.
    For example, if you had a simple log method:
    private void log (String tempString)
    if (logFile.length > 1048576)
    pbuffer.close();
    logFile.close();
    DateFormat df = new SimpleDateFormat("ddMMyy");
    String tempString = df.format(calendar.getTime());
    File file = new File("C:/log" + tempString + System.currentTimeMillis() + ".txt");
    pbuffer = new BufferedWriter(new FileWriter(file.getName()));
    pbuffer.write(tempString);
    }The example depends on what you are using to write the file...here I am just using a simple BufferedWriter to do all the file writing. Maybe this will help you however. :)

  • Cannot open shared object file: on Informatica Power Centre(8.1.1) Installa

    Hi Friends,
    I am trying to install Informatica Power Centre 8.1.1 and when i invoke the installet it' giving below error:
    My OS is Redhat Linux (64 bit).
    What's the issue?
    onfiguring the installer for this system's environment...
    awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
    dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    /bin/ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
    basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    Launching installer...
    grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    /tmp/install.dir.28135/Linux/resource/jre/jre/bin/java: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory
    [oracle@obidb PowerCenter_8.1.1_SE_for_Linux_x64_64Bit]$
    Regards,
    DB

    Hi;
    I am in the process of installing R12.1.1 on RHEL5(64-bit). All the pre-req have been done.. I did the installation twice but I am facing the same issue. When i try to run adconfig.sh on the appsTier. i get the following errorYou want to run adconfig.sh on appstier or dbtier?
    If you run appstier be sure you source env file with applmgr user
    Regard
    Helios

  • Cannot open shared object file: on Informatica Power Centre Installation

    Hi Friends,
    I am trying to install Informatica Power Centre 8.1.1 and when i invoke the installet it' giving below error:
    My OS is Redhat Linux (64 bit).
    What's the issue?
    onfiguring the installer for this system's environment...
    awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
    dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    /bin/ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
    basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    Launching installer...
    grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    /tmp/install.dir.28135/Linux/resource/jre/jre/bin/java: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory
    [oracle@obidb PowerCenter_8.1.1_SE_for_Linux_x64_64Bit]$
    Regards,
    DB

    Hi;
    I am in the process of installing R12.1.1 on RHEL5(64-bit). All the pre-req have been done.. I did the installation twice but I am facing the same issue. When i try to run adconfig.sh on the appsTier. i get the following errorYou want to run adconfig.sh on appstier or dbtier?
    If you run appstier be sure you source env file with applmgr user
    Regard
    Helios

  • How to read an XML file into a java program?

    hi,
    i want to load the following very simple xml file in my java program.
    <root>
    <weblogic>
    <url value="t3://192.168.1.160:7001" />
    <context value="weblogic.jndi.WLInitialContextFactory" />
    </weblogic>
    </root>
    I am getting the error: " Line=1: cvc-elt.1: Cannot find the declaration of element 'root'."
    What might be the problem can anyone help me out.
    My java class code is:
    public class BIXMLReader {
    /** All output will use this encoding */
    static final String outputEncoding = "UTF-8";
    // Parses an XML file and returns a DOM document.
    // If validating is true, the contents is validated against the DTD
    // specified in the file.
    public static Document parseXmlFile(String filename, boolean validating) {
    try {
    // Create a builder factory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setIgnoringComments(false);
    factory.setIgnoringElementContentWhitespace(false);
    factory.setCoalescing(false);
    factory.setValidating(validating);
    // Create the builder and parse the file
    System.out.println("filename = " + filename);
    DocumentBuilder db = factory.newDocumentBuilder();
    // Set an ErrorHandler before parsing
    OutputStreamWriter errorWriter = new OutputStreamWriter(System.err, outputEncoding);
    db.setErrorHandler(new MyErrorHandler(new PrintWriter(errorWriter, true)));
    Document doc = db.parse(new File(filename));
    System.out.println(doc.toString());
    return doc;
    } catch (SAXException e) {
    System.out.println("A parsing error occurred; the xml input is not valid. " + e.getMessage());
    } catch (ParserConfigurationException e) {
    System.out.println("Parser configuration exception has occured");
    } catch (IOException e) {
    System.out.println("IO Exception has occured " + e.getMessage());
    return null;
    // Error handler to report errors and warnings
    private static class MyErrorHandler implements ErrorHandler {
    /** Error handler output goes here */
    private PrintWriter out;
    MyErrorHandler(PrintWriter out) {
    this.out = out;
    * Returns a string describing parse exception details
    private String getParseExceptionInfo(SAXParseException spe) {
    String systemId = spe.getSystemId();
    if (systemId == null) {
    systemId = "null";
    String info = "URI=" + systemId +
    " Line=" + spe.getLineNumber() +
    ": " + spe.getMessage();
    return info;
    // The following methods are standard SAX ErrorHandler methods.
    // See SAX documentation for more info.
    public void warning(SAXParseException spe) throws SAXException {
    out.println("Warning: " + getParseExceptionInfo(spe));
    public void error(SAXParseException spe) throws SAXException {
    String message = "Error: " + getParseExceptionInfo(spe);
    throw new SAXException(message);
    public void fatalError(SAXParseException spe) throws SAXException {
    String message = "Fatal Error: " + getParseExceptionInfo(spe);
    throw new SAXException(message);
    }

    ok thanks, i can get the elements, but why did it not validate it?
    I want to read the child nodes of "weblogic" not by their name but by their index. Because i dont want to confine the reader so i want to read all the child nodes of weblogic (looping over them). i m doing the following but its not returning me the correct result and giving me the wrong count of child nodes.
    Element elementNode = (Element)doc.getElementsByTagName("weblogic").item(0);
    NodeList nodeList = elementNode.getChildNodes();
    int length = nodeList.getLength();
    System.out.println("length = "+ length); // the length its giving is 5 but i shuld get only 2
    for(int i=0; i < length; i++) {
    Element elmChild = (Element) nodeList.item(i);
    System.out.println(elmChild.getAttribute("value"));
    what might be the problem?

Maybe you are looking for

  • Alphabetically ordering a Linked List

    Would anyone please be able to give me help in ordering a linked list alphabetically. I'm new to java so please be gentle. Many thanks in advance.

  • Still loose ability to drag and drop files in Project pane.

    In the last two weeks, I've had two instances where I lost the ability to drag and drop files within the Project pane. However, here's the kicker...the problem doesn't manefest itself until after I end my session, close RH, then restart the computer

  • Indesign CS 5.5 Crashes When opening certain file

    Hi, We have a user who is having issues opening a certain indesign document. If they open the document it will appear to load but after a few seconds it will stop working. 'Adobe CS5.5 has stopped working' They are using Windows 7 x64. I recently app

  • Acrobat Pro X - How to allow user to save form with data

    I'm evaluating the trial version to make sure it does what we want.  I want the user to be able to save a form to their PC with the data they've typed in.  In my search of the forums I found an answer that said to look at File > Save As > Reader Exte

  • Sennheiser PC 136 USB headset in MAC OS 10.8

    Dear Apple support, I'm having troubles with my old headset which just appeared after my 10.7 -> 10.8 MAC OS upgrade few weeks ago. http://www.sennheisercommunications.com/ Problem description: The system somehow doesn't recognize and switch by defau