Package java.io

Examples of java.io.ObjectInputStream


          case VIRTUAL:
            final int nfrag = rawContentDataInputStream.readInt();
            for ( int i = 0; i < 2 * nfrag; i++ ) MutableString.skipSelfDelimUTF8( rawContent );
            break;
          default: // Non-text and non-virtual
            new ObjectInputStream( rawContent ).readObject();
          }
          nextFieldToRead++;
        }
       
        /** Skips to the given field.
         *
         * @param field the field to skip to.
         * @throws IOException
         * @throws ClassNotFoundException
         */
        private void skipToField( final int field ) throws IOException, ClassNotFoundException {
          if ( nextFieldToRead > field ) throw new IllegalStateException( "Trying to skip to field " + field + " after " + nextFieldToRead );
          while ( nextFieldToRead < field ) skipOneField();
        }

        public Object content( final int field ) {
          ensureFieldIndex( field );
          Object result = null;
          if ( DEBUG ) LOGGER.debug( "Called content(" + field + "); nextField:" + nextFieldToRead );
          try {
            skipToField( field );
            if ( fieldType( nextFieldToRead ) == FieldType.VIRTUAL ) {
              final int nfrag = rawContentDataInputStream.readInt();
              MutableString doc = new MutableString();
              MutableString text = new MutableString();
              VirtualDocumentFragment[] fragArray = new VirtualDocumentFragment[ nfrag ];
              for ( int i = 0; i < nfrag; i++ ) {
                doc.readSelfDelimUTF8( rawContent );
                text.readSelfDelimUTF8( rawContent );
                fragArray[ i ] = new AnchorExtractor.Anchor( doc.copy(), text.copy() );
              }
              result = new ObjectArrayList<VirtualDocumentFragment>( fragArray );
            }
            else if ( fieldType( nextFieldToRead ) != FieldType.TEXT ) {
              result = new ObjectInputStream( rawContent ).readObject();
              if ( DEBUG ) LOGGER.debug( "Read " + result + " from field " + fieldName( nextFieldToRead ) + " of object " + title() );
              nextFieldToRead++;
            }
            else {
              if ( DEBUG ) LOGGER.debug( "Returning reader for " + field );
View Full Code Here


          case VIRTUAL:
            final int nfrag = nonTextDataInputStream.readInt();
            for ( int i = 0; i < 2 * nfrag; i++ ) MutableString.skipSelfDelimUTF8( nonTextDataInputStream );
            break;
          default:
            try { new ObjectInputStream( nonTextDataInputStream ).readObject(); } catch ( ClassNotFoundException e ) { throw new RuntimeException( e ); }
          }
          nextField++;
        }
       
        // Read field
        nextField++;

        switch( fieldType ) {
        case TEXT:
          len = documentsInputBitStream.readDelta();
          fieldContent.length( 0 );

          termsFrequencyKeeper.reset();
          if ( exact ) nonTermsFrequencyKeeper.reset();

          while( len-- != 0 ) {
            termsInputStream.position( termOffsets.getLong( termsFrequencyKeeper.decode( documentsInputBitStream.readDelta() ) ) );
            s.readSelfDelimUTF8( termsInputStream );
            fieldContent.append( s );
            if ( exact ) {
              nonTermsInputStream.position( nonTermOffsets.getLong( nonTermsFrequencyKeeper.decode( documentsInputBitStream.readDelta() ) ) );
              s.readSelfDelimUTF8( nonTermsInputStream );
              fieldContent.append( s );
            }
            else fieldContent.append( ' ');
          }
          return new FastBufferedReader( fieldContent );
        case VIRTUAL:
          final int nfrag = nonTextDataInputStream.readInt();
          MutableString doc = new MutableString();
          MutableString text = new MutableString();
          VirtualDocumentFragment[] fragArray = new VirtualDocumentFragment[ nfrag ];
          for ( int i = 0; i < nfrag; i++ ) {
            doc.readSelfDelimUTF8( (InputStream)nonTextDataInputStream );
            text.readSelfDelimUTF8( (InputStream)nonTextDataInputStream );
            fragArray[ i ] = new AnchorExtractor.Anchor( doc.copy(), text.copy() );
          }
          return new ObjectArrayList<VirtualDocumentFragment>( fragArray );

        default:
          try { return new ObjectInputStream( nonTextDataInputStream ).readObject(); } catch ( ClassNotFoundException e ) { throw new RuntimeException( e ); }
        }
     
       
      }

View Full Code Here

    // need to do this check because we are a stream type
    if (bytes == null) {
      return null;
    }
    try {
      ObjectInputStream objInStream = new ObjectInputStream(new ByteArrayInputStream(bytes));
      return objInStream.readObject();
    } catch (Exception e) {
      throw SqlExceptionUtil.create("Could not read serialized object from byte array: " + Arrays.toString(bytes)
          + "(len " + bytes.length + ")", e);
    }
  }
View Full Code Here

        if (!isRpc) {
          List params = constructParams(method, modelMap);
          args = params.size() > 0 ? params.toArray() : null;
        } else {
          byte[] bytes = (byte[]) modelMap.get(ModelMap.RPC_ARGS_KEY);
          ObjectInputStream obj_in = new ObjectInputStream(
              new ByteArrayInputStream(bytes));
          args = (Object[]) obj_in.readObject();
        }

        // 执行业务方法
        result = method.invoke(instance, args);
View Full Code Here

                }
            }
        }
    }
    public static DiskCacheObject deSerialize(byte[] data) throws DiskCacheException {
        ObjectInputStream ois = null;
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            BufferedInputStream bis = new BufferedInputStream(bais);
            ois=new ObjectInputStream(bis);
            DiskCacheObject obj = (DiskCacheObject) ois.readObject();
            obj.getCacheObject().resetRefCount();
            return obj;
        } catch (IOException e) {
            throw new IllegalStateException("An exception occured when reading from the disk cache." +
                " Reason: " + e.getMessage());
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException("A class could not be found when deSerializing." +
                " Reason: " + e.getMessage());
        } finally {
          if (ois != null) {
              try {
                  ois.close();
              } catch (IOException e) {
                  throw new IllegalStateException(
                      "Failed to close stream to DiskCache, "
                      + "cache may be corrupted. Reason: " + e.getMessage());
              }
View Full Code Here

   *          input stream to read from
   * @throws IOException
   *           any usual I/O errors
   */
  public PacketInputStream(InputStream in) throws IOException {
    this.in = new ObjectInputStream(in);

  }
View Full Code Here

    final ByteArrayOutputStream bo = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bo);
    out.writeObject(cpd);
    out.close();

    final ObjectInputStream oin = new ObjectInputStream
      (new ByteArrayInputStream(bo.toByteArray()));
    final Object e2 = oin.readObject();
    assertNotNull(e2); // cannot assert equals, as this is not implemented.
    assertEquals(cpd, e2);
  }
View Full Code Here

    final ByteArrayOutputStream bo = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bo);
    out.writeObject(cpd);
    out.close();

    final ObjectInputStream oin = new ObjectInputStream
      (new ByteArrayInputStream(bo.toByteArray()));
    final Object e2 = oin.readObject();
    assertNotNull(e2); // cannot assert equals, as this is not implemented.
    assertEquals(cpd, e2);
  }
View Full Code Here

    final Element e = new Element();
    final ByteArrayOutputStream bo = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bo);
    out.writeObject(e);

    final ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bo.toByteArray()));
    final Element e2 = (Element) oin.readObject();
    assertNotNull(e2); // cannot assert equals, as this is not implemented ...
  }
View Full Code Here

    final MasterReport report = new MasterReport();
    final ByteArrayOutputStream bo = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bo);
    out.writeObject(report);

    final ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bo.toByteArray()));
    final MasterReport e2 = (MasterReport) oin.readObject();
    assertNotNull(e2); // cannot assert equals, as this is not implemented.
  }
View Full Code Here

TOP

Related Classes of java.io.ObjectInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.