📄 compositebytearray.java
字号:
{ prepareForAccess( 1 ); byte b = componentCursor.get(); index += 1; return b; } /** * @inheritDoc */ public void put( byte b ) { prepareForAccess( 1 ); componentCursor.put( b ); index += 1; } /** * @inheritDoc */ public void get( IoBuffer bb ) { while ( bb.hasRemaining() ) { int remainingBefore = bb.remaining(); prepareForAccess( remainingBefore ); componentCursor.get( bb ); int remainingAfter = bb.remaining(); // Advance index by actual amount got. int chunkSize = remainingBefore - remainingAfter; index += chunkSize; } } /** * @inheritDoc */ public void put( IoBuffer bb ) { while ( bb.hasRemaining() ) { int remainingBefore = bb.remaining(); prepareForAccess( remainingBefore ); componentCursor.put( bb ); int remainingAfter = bb.remaining(); // Advance index by actual amount put. int chunkSize = remainingBefore - remainingAfter; index += chunkSize; } } /** * @inheritDoc */ public short getShort() { prepareForAccess( 2 ); if ( componentCursor.getRemaining() >= 4 ) { short s = componentCursor.getShort(); index += 2; return s; } else { byte b0 = get(); byte b1 = get(); if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { return ( short ) ( ( b0 << 8 ) | ( b1 << 0 ) ); } else { return ( short ) ( ( b1 << 8 ) | ( b0 << 0 ) ); } } } /** * @inheritDoc */ public void putShort( short s ) { prepareForAccess( 2 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putShort( s ); index += 2; } else { byte b0; byte b1; if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { b0 = ( byte ) ( ( s >> 8 ) & 0xff ); b1 = ( byte ) ( ( s >> 0 ) & 0xff ); } else { b0 = ( byte ) ( ( s >> 0 ) & 0xff ); b1 = ( byte ) ( ( s >> 8 ) & 0xff ); } put( b0 ); put( b1 ); } } /** * @inheritDoc */ public int getInt() { prepareForAccess( 4 ); if ( componentCursor.getRemaining() >= 4 ) { int i = componentCursor.getInt(); index += 4; return i; } else { byte b0 = get(); byte b1 = get(); byte b2 = get(); byte b3 = get(); if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { return ( ( b0 << 24 ) | ( b1 << 16 ) | ( b2 << 8 ) | ( b3 << 0 ) ); } else { return ( ( b3 << 24 ) | ( b2 << 16 ) | ( b1 << 8 ) | ( b0 << 0 ) ); } } } /** * @inheritDoc */ public void putInt( int i ) { prepareForAccess( 4 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putInt( i ); index += 4; } else { byte b0; byte b1; byte b2; byte b3; if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { b0 = ( byte ) ( ( i >> 24 ) & 0xff ); b1 = ( byte ) ( ( i >> 16 ) & 0xff ); b2 = ( byte ) ( ( i >> 8 ) & 0xff ); b3 = ( byte ) ( ( i >> 0 ) & 0xff ); } else { b0 = ( byte ) ( ( i >> 0 ) & 0xff ); b1 = ( byte ) ( ( i >> 8 ) & 0xff ); b2 = ( byte ) ( ( i >> 16 ) & 0xff ); b3 = ( byte ) ( ( i >> 24 ) & 0xff ); } put( b0 ); put( b1 ); put( b2 ); put( b3 ); } } /** * @inheritDoc */ public long getLong() { prepareForAccess( 8 ); if ( componentCursor.getRemaining() >= 4 ) { long l = componentCursor.getLong(); index += 8; return l; } else { byte b0 = get(); byte b1 = get(); byte b2 = get(); byte b3 = get(); byte b4 = get(); byte b5 = get(); byte b6 = get(); byte b7 = get(); if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { return ( ( b0 & 0xffL ) << 56 ) | ( ( b1 & 0xffL ) << 48 ) | ( ( b2 & 0xffL ) << 40 ) | ( ( b3 & 0xffL ) << 32 ) | ( ( b4 & 0xffL ) << 24 ) | ( ( b5 & 0xffL ) << 16 ) | ( ( b6 & 0xffL ) << 8 ) | ( ( b7 & 0xffL ) << 0 ); } else { return ( ( b7 & 0xffL ) << 56 ) | ( ( b6 & 0xffL ) << 48 ) | ( ( b5 & 0xffL ) << 40 ) | ( ( b4 & 0xffL ) << 32 ) | ( ( b3 & 0xffL ) << 24 ) | ( ( b2 & 0xffL ) << 16 ) | ( ( b1 & 0xffL ) << 8 ) | ( ( b0 & 0xffL ) << 0 ); } } } /** * @inheritDoc */ public void putLong( long l ) { //TODO: see if there is some optimizing that can be done here prepareForAccess( 8 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putLong( l ); index += 8; } else { byte b0; byte b1; byte b2; byte b3; byte b4; byte b5; byte b6; byte b7; if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { b0 = ( byte ) ( ( l >> 56 ) & 0xff ); b1 = ( byte ) ( ( l >> 48 ) & 0xff ); b2 = ( byte ) ( ( l >> 40 ) & 0xff ); b3 = ( byte ) ( ( l >> 32 ) & 0xff ); b4 = ( byte ) ( ( l >> 24 ) & 0xff ); b5 = ( byte ) ( ( l >> 16 ) & 0xff ); b6 = ( byte ) ( ( l >> 8 ) & 0xff ); b7 = ( byte ) ( ( l >> 0 ) & 0xff ); } else { b0 = ( byte ) ( ( l >> 0 ) & 0xff ); b1 = ( byte ) ( ( l >> 8 ) & 0xff ); b2 = ( byte ) ( ( l >> 16 ) & 0xff ); b3 = ( byte ) ( ( l >> 24 ) & 0xff ); b4 = ( byte ) ( ( l >> 32 ) & 0xff ); b5 = ( byte ) ( ( l >> 40 ) & 0xff ); b6 = ( byte ) ( ( l >> 48 ) & 0xff ); b7 = ( byte ) ( ( l >> 56 ) & 0xff ); } put( b0 ); put( b1 ); put( b2 ); put( b3 ); put( b4 ); put( b5 ); put( b6 ); put( b7 ); } } /** * @inheritDoc */ public float getFloat() { prepareForAccess( 4 ); if ( componentCursor.getRemaining() >= 4 ) { float f = componentCursor.getFloat(); index += 4; return f; } else { int i = getInt(); return Float.intBitsToFloat( i ); } } /** * @inheritDoc */ public void putFloat( float f ) { prepareForAccess( 4 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putFloat( f ); index += 4; } else { int i = Float.floatToIntBits( f ); putInt( i ); } } /** * @inheritDoc */ public double getDouble() { prepareForAccess( 8 ); if ( componentCursor.getRemaining() >= 4 ) { double d = componentCursor.getDouble(); index += 8; return d; } else { long l = getLong(); return Double.longBitsToDouble( l ); } } /** * @inheritDoc */ public void putDouble( double d ) { prepareForAccess( 8 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putDouble( d ); index += 8; } else { long l = Double.doubleToLongBits( d ); putLong( l ); } } /** * @inheritDoc */ public char getChar() { prepareForAccess( 2 ); if ( componentCursor.getRemaining() >= 4 ) { char c = componentCursor.getChar(); index += 2; return c; } else { byte b0 = get(); byte b1 = get(); if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { return ( char ) ( ( b0 << 8 ) | ( b1 << 0 ) ); } else { return ( char ) ( ( b1 << 8 ) | ( b0 << 0 ) ); } } } /** * @inheritDoc */ public void putChar( char c ) { prepareForAccess( 2 ); if ( componentCursor.getRemaining() >= 4 ) { componentCursor.putChar( c ); index += 2; } else { byte b0; byte b1; if ( order.equals( ByteOrder.BIG_ENDIAN ) ) { b0 = ( byte ) ( ( c >> 8 ) & 0xff ); b1 = ( byte ) ( ( c >> 0 ) & 0xff ); } else { b0 = ( byte ) ( ( c >> 0 ) & 0xff ); b1 = ( byte ) ( ( c >> 8 ) & 0xff ); } put( b0 ); put( b1 ); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -