Package java.io

Examples of java.io.DataInputStream


      command = socket.getInputStream().read();
      LOGGER.debug( "Remote command: " + command );
     
      switch( command ) {
      case GET_INDEX:
        DataInputStream dis = new DataInputStream( socket.getInputStream() );
        DataOutputStream dos = new DataOutputStream( socket.getOutputStream() );
        boolean randomAccess = dis.readBoolean();
        boolean documentSizes = dis.readBoolean();
       
        if ( index instanceof BitStreamIndex && ! forceRemoteIndex ) {
          BitStreamIndex localIndex = (BitStreamIndex)index;
          if ( randomAccess && localIndex.offsets == null ) {
            randomAccess = false;
View Full Code Here


 
  public Document document( int index ) throws IOException {
    ensureDocumentIndex( index );
    ensureFiles();
    documentsInputBitStream.position( docOffsets.getLong( index ) );
    final DataInputStream nonTextDataInputStream = hasNonText ? new DataInputStream( new FastBufferedInputStream( zipFile.getInputStream( zipFile.getEntry( Integer.toString( index ) ) ) ) ) : null;
    final MutableString uri = readSelfDelimitedUtf8String( documentsInputBitStream, new MutableString() );
    final MutableString title = readSelfDelimitedUtf8String( documentsInputBitStream, new MutableString() );

    return new AbstractDocument() {
      final MutableString fieldContent = new MutableString();
     
      @SuppressWarnings("unchecked")
      final Document fakeDocument = factory.getDocument( NullInputStream.getInstance(), Reference2ObjectMaps.EMPTY_MAP );
     
      int nextField = 0;

      public Object content( int field ) throws IOException {
        FieldType fieldType = factory.fieldType( field );

        if ( nextField > field ) throw new IllegalStateException();
        // Skip fields
        final MutableString s = new MutableString();
        int len;
        while( nextField < field ) {
          switch( fieldType ) {
          case TEXT:
            len = documentsInputBitStream.readDelta();
            if ( exact ) len *= 2;
            documentsInputBitStream.skipDeltas( len );
            break;
          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 ); }
        }
     
       
      }

      public CharSequence title() {
        return title;
      }

      public CharSequence uri() {
        return uri.length() == 0 ? null : uri;
      }

      public WordReader wordReader( int field ) {
        switch( factory.fieldType( field ) ) {
        case TEXT:
        case VIRTUAL: return fakeDocument.wordReader( field );
        default: return null;
        }
      }
     
      public void close() throws IOException {
        super.close();
        if ( hasNonText ) nonTextDataInputStream.close();
      }

    };
  }
View Full Code Here

     
      return( null );
    }
   
    try{
      DataInputStream  dis = new DataInputStream( new ByteArrayInputStream( value.getValue()));
     
      final DHTStorageKeyStats stats = storage_manager.deserialiseStats( dis );
     
      return(
        new DHTPluginKeyStats()
View Full Code Here

        target  = new File( data_dir, "contacts.saving" );
      }

      if ( target.exists()){
       
        DataInputStream  dis =  new DataInputStream( new FileInputStream( target ));
       
        try{
         
          dht.importState( dis );
         
        }finally{
                     
          dis.close();
        }
      }
    }catch( Throwable e ){
     
      Debug.printStackTrace( e );
View Full Code Here

     
      data = new byte[0];
    }
   
    try{
      provider.startUp( new DataInputStream( new ByteArrayInputStream( data )));
     
    }catch( Throwable e ){
     
      Debug.printStackTrace( e );
    }
View Full Code Here

    
       throws IOException
     {
       ByteArrayInputStream  bais = new ByteArrayInputStream( bytes );
      
       DataInputStream  dis = new DataInputStream( bais );
    
       dis.readByte()// version
      
       byte  position_type = dis.readByte();
      
       return( deserialise( originator, position_type, dis ));
     }
View Full Code Here

         
          dos.writeInt( beacon_out.length );   
       
          dos.write( beacon_out );       
           
          DataInputStream dis = new DataInputStream( socket.getInputStream());
         
          int len = dis.readInt();
       
          if ( len < 65536 ){
           
            byte[] bytes = new byte[len];
 
            int  pos = 0;
           
            while( pos < len ){
           
              int read = dis.read( bytes, pos, len-pos );
             
              pos += read;
            }
           
            Map<String,String> beacon_in = _tivo_manager.decodeBeacon( bytes, len );
View Full Code Here

      byte[]  bytes = result_value[0].getValue();
     
      try{
        ByteArrayInputStream  bais = new ByteArrayInputStream( bytes );
       
        DataInputStream  dis = new DataInputStream( bais );
       
        byte  version = dis.readByte();
       
        if ( version != 0 ){
         
          throw( new Exception( "Unsupported rendezvous version '" + version + "'" ));
        }
View Full Code Here

    byte[]    bytes )
  {
    try{
      ByteArrayInputStream  bais = new ByteArrayInputStream( bytes );
     
      DataInputStream  dis = new DataInputStream( bais );
           
      return((DHTTransportUDPContact)dht.getTransport().importContact( dis ));
     
    }catch( Throwable e ){
     
View Full Code Here

    public void run() {
        try {
            server.trace("Connect");
            InputStream ins = socket.getInputStream();
            out = socket.getOutputStream();
            dataInRaw = new DataInputStream(ins);
            while (!stop) {
                process();
                out.flush();
            }
        } catch (EOFException e) {
View Full Code Here

TOP

Related Classes of java.io.DataInputStream

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.