⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lerandomaccessfile.java

📁 java base64
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               ( long ) ( work[ 6 ] & 0xff ) << 48
               | ( long ) ( work[ 5 ] & 0xff ) << 40
               | ( long ) ( work[ 4 ] & 0xff ) << 32
               | ( long ) ( work[ 3 ] & 0xff ) << 24
               | ( long ) ( work[ 2 ] & 0xff ) << 16
               | ( long ) ( work[ 1 ] & 0xff ) << 8
               | ( long ) ( work[ 0 ] & 0xff );
        }

    /**
     * Read a short, 16 bits.
     *
     * @return short read. like RandomAcessFile.readShort except little endian.
     * @throws IOException if read fails.
     */
    public final short readShort() throws IOException
        {
        raf.readFully( work, 0, 2 );
        return ( short ) ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
        }

    /**
     * Read a counted UTF-8 string.
     *
     * @return string read.
     * @throws IOException if read fails.
     */
    public final String readUTF() throws IOException
        {
        return raf.readUTF();
        }

    /**
     * return an unsigned byte. Noote: returns an int, even though says Byte.
     *
     * @return the byte read.
     * @throws IOException if read fails.
     */
    public final int readUnsignedByte() throws IOException
        {
        return raf.readUnsignedByte();
        }

    /**
     * Read an unsigned short, 16 bits. Like RandomAcessFile.readUnsignedShort except little endian. Note, returns int
     * even though it reads a short.
     *
     * @return little-endian unsigned short, as an int.
     * @throws IOException if read fails.
     */
    public final int readUnsignedShort() throws IOException
        {
        raf.readFully( work, 0, 2 );
        return ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
        }

    /**
     * seek to a place in the file
     *
     * @param pos 0-based offset to seek to.
     * @throws IOException if read fails.
     * @noinspection SameParameterValue
     */
    public final void seek( long pos ) throws IOException
        {
        raf.seek( pos );
        }

    /**
     * Skip over bytes.
     *
     * @param n number of bytes to skip over.
     * @return the actual number of bytes skipped.
     * @throws IOException if read fails.
     */
    public final int skipBytes( int n ) throws IOException
        {
        return raf.skipBytes( n );
        }

    /**
     * Write a byte. Only writes one byte even though says int.
     *
     * @param ib byte to write.
     * @throws IOException if read fails.
     */
    public final synchronized void write( int ib ) throws IOException
        {
        raf.write( ib );
        }

    /**
     * Write an array of bytes.
     *
     * @param ba array to write.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#write(byte[])
     */
    public final void write( byte ba[] ) throws IOException
        {
        raf.write( ba, 0, ba.length );
        }

    /**
     * Write part of an array of bytes.
     *
     * @param ba  array to write.
     * @param off offset
     * @param len count of bytes to write.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#write(byte[],int,int)
     */
    public final synchronized void write( byte ba[],
                                          int off,
                                          int len ) throws IOException
        {
        raf.write( ba, off, len );
        }

    /**
     * write a boolean as one byte.
     *
     * @param v boolean to write.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#writeBoolean(boolean)
     */
    public final void writeBoolean( boolean v ) throws IOException
        {
        raf.writeBoolean( v );
        }

    /**
     * Write a byte. Note param is an int though only a byte is written.
     *
     * @param v byte to write.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#writeByte(int)
     */
    public final void writeByte( int v ) throws IOException
        {
        raf.writeByte( v );
        }

    /**
     * Write bytes from a String.
     *
     * @param s string source of the bytes.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#writeBytes(java.lang.String)
     */
    public final void writeBytes( String s ) throws IOException
        {
        raf.writeBytes( s );
        }

    /**
     * Write a char.  note param is an int though writes a char.
     *
     * @param v char to write. like RandomAcessFile.writeChar. Note the parm is an int even though this as a writeChar
     * @throws IOException if read fails.
     */
    public final void writeChar( int v ) throws IOException
        {
        // same code as writeShort
        work[ 0 ] = ( byte ) v;
        work[ 1 ] = ( byte ) ( v >> 8 );
        raf.write( work, 0, 2 );
        }

    /**
     * Write a string, even though method called writeChars. like RandomAcessFile.writeChars, has to flip each char.
     *
     * @param s Strinhg to write.
     * @throws IOException if read fails.
     */
    public final void writeChars( String s ) throws IOException
        {
        int len = s.length();
        for ( int i = 0; i < len; i++ )
            {
            writeChar( s.charAt( i ) );
            }
        }// end writeChars

    /**
     * Write a double. Like RandomAcessFile.writeDouble.
     *
     * @param v double to write.
     * @throws IOException if read fails.
     */
    public final void writeDouble( double v ) throws IOException
        {
        writeLong( Double.doubleToLongBits( v ) );
        }

    /**
     * Write a float. Like RandomAcessFile.writeFloat.
     *
     * @param v float to write.
     * @throws IOException if read fails.
     */
    public final void writeFloat( float v ) throws IOException
        {
        writeInt( Float.floatToIntBits( v ) );
        }

    /**
     * write an int, 32-bits. Like RandomAcessFile.writeInt.
     *
     * @param v int to write.
     * @throws IOException if read fails.
     */
    public final void writeInt( int v ) throws IOException
        {
        work[ 0 ] = ( byte ) v;
        work[ 1 ] = ( byte ) ( v >> 8 );
        work[ 2 ] = ( byte ) ( v >> 16 );
        work[ 3 ] = ( byte ) ( v >> 24 );
        raf.write( work, 0, 4 );
        }

    /**
     * Write i long, 64 bits. Like java.io.RandomAccessFile.writeLong.
     *
     * @param v long write.
     * @throws IOException if read fails.
     * @see java.io.RandomAccessFile#writeLong
     */
    public final void writeLong( long v ) throws IOException
        {
        work[ 0 ] = ( byte ) v;
        work[ 1 ] = ( byte ) ( v >> 8 );
        work[ 2 ] = ( byte ) ( v >> 16 );
        work[ 3 ] = ( byte ) ( v >> 24 );
        work[ 4 ] = ( byte ) ( v >> 32 );
        work[ 5 ] = ( byte ) ( v >> 40 );
        work[ 6 ] = ( byte ) ( v >> 48 );
        work[ 7 ] = ( byte ) ( v >> 56 );
        raf.write( work, 0, 8 );
        }

    /**
     * Write an signed short even though parameter is an int. Like java.io.RandomAcessFile#writeShort. also acts as a
     * writeUnsignedShort.
     *
     * @param v signed number to write
     * @throws IOException if read fails.
     */
    public final void writeShort( int v ) throws IOException
        {
        work[ 0 ] = ( byte ) v;
        work[ 1 ] = ( byte ) ( v >> 8 );
        raf.write( work, 0, 2 );
        }

    /**
     * Write a counted UTF string.
     *
     * @param s String to write.
     * @throws IOException if read fails.
     * @see java.io.DataOutput#writeUTF(java.lang.String)
     */
    public final void writeUTF( String s ) throws IOException
        {
        raf.writeUTF( s );
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -