Package java.io

Examples of java.io.DataInputStream


            if ( m_debug )
            {
                m_outDebug.println( getRes().getString( "handleBackend()" ) );
            }

            DataInputStream is = new DataInputStream( m_backendIS );
            while ( !m_disposed )
            {
                // A Packet code must exist.
                byte code = is.readByte();
               
                // Always read from the buffer until a null '\0' is encountered.
                byte b;
                int i = 0;
                do
                {
                    b = is.readByte();
                    if ( b != 0 )
                    {
                        if ( i >= m_backendReadBuffer.length )
                        {
                            byte[] tmp = m_backendReadBuffer;
View Full Code Here


        byte[] src = new byte[8];
        src[0] = (byte)1;
        src[2] = (byte)1;
        src[4] = (byte)1;
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);
        LinkedBufferInput b2 = new LinkedBufferInput(8);
        b2.feed(src);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        try {
            b2.readByte();
            fail();
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

            }
        }

        byte[] src = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(src);
        DataInputStream b1 = new DataInputStream(bin);

        for(int i=0; i < src.length; i++) {
            assertEquals(b1.readByte(), b2.readByte());
        }

        assertEndOfBuffer(b2);
    }
View Full Code Here

     */
    public boolean doPlayerPrefetch() {
        //  Has the data already been prefetched?
        if( ! prefetchNeeded ) return true;

        DataInputStream in = null;
        byte[] b;

        try {
            //  Create an input stream
            in = new DataInputStream(
                new PullSourceInputStream(stream) );

            //  Get the length
            long length = stream.getContentLength();

            if( length != SourceStream.LENGTH_UNKNOWN ) {
                //  Load the entire text file into a byte array
                b = new byte[(int)length];
                in.readFully(b,0,(int)length);
            } else {
                System.err.println(
                    "Unknown content length while reading data");

                postEvent(
                    new ResourceUnavailableEvent(this,
                        "Could not get content length from data stream") );

                return false;
            }
        }
       
        catch(EOFException e) {
            System.err.println("Unexpected EOF while reading data");

            postEvent(
                new ResourceUnavailableEvent(this,
                    "Unexpected EOF occurred while reading data stream") );

            return false;
           
        }

        catch(IOException e) {
            System.err.println("I/O Error reading data");

            postEvent(
                new ResourceUnavailableEvent(this,
                    "I/O error occurred while reading data stream") );

            return false;
        }
       
        finally {
            try { in.close(); } catch(Exception e) {}
        }

        //  Convert the byte array to a String and set the
        //  TickerTape message
        tape.setMessage( new String(b,0,b.length) );
View Full Code Here

   public void read(InputStream in,boolean clientMode) throws SocksException,
                                           IOException{
      data = null;
      ip = null;

      DataInputStream di = new DataInputStream(in);

      version = di.readUnsignedByte();
      command = di.readUnsignedByte();
      if(clientMode && command != 0)
        throw new SocksException(command);

      int reserved = di.readUnsignedByte();
      addrType = di.readUnsignedByte();

      byte addr[];

      switch(addrType){
         case SOCKS_ATYP_IPV4:
            addr = new byte[4];
            di.readFully(addr);
            host = bytes2IPV4(addr,0);
         break;
         case SOCKS_ATYP_IPV6:
           addr = new byte[SOCKS_IPV6_LENGTH];//I believe it is 16 bytes,huge!
           di.readFully(addr);
           host = bytes2IPV6(addr,0);
         break;
         case SOCKS_ATYP_DOMAINNAME:
           //System.out.println("Reading ATYP_DOMAINNAME");
           addr = new byte[di.readUnsignedByte()];//Next byte shows the length
           di.readFully(addr);
           host = new String(addr);
         break;
         default:
            throw(new SocksException(Proxy.SOCKS_JUST_ERROR));
      }

      port = di.readUnsignedShort();

      if(addrType != SOCKS_ATYP_DOMAINNAME && doResolveIP){
         try{
            ip = InetAddress.getByName(host);
         }catch(UnknownHostException uh_ex){
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.