home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
ByteArrayStore.java
< prev
next >
Wrap
Text File
|
1998-09-08
|
6KB
|
191 lines
package com.symantec.itools.util;
import com.symantec.itools.lang.Machine;
import java.net.*;
/**
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class ByteArrayStore
{
/**
* @param barr TODO
* @param start TODO
* @since VCafe 3.0
*/
/* Integer operations */
public static final int constructInt( int[] barr, int start )
{
int j;
int k;
int i = 0;
for ( k = 0, j = Machine.SIZEOF_INT - 1; j > -1; j--, k++ )
{
// i |= barr[ start + j ] << (j*Machine.WIDTHOF_BYTE);
/*
The int mask, ((int)0xFF << (j* Machine.WIDTHOF_BYTE ), is needed because
Java does sign aware widening. So something like (byte)0x80 widens to
0xFF80. Of course this screws things up when you try to OR into i the shifted
byte.
*/
i |= ( barr[ start + k ] << (j* Machine.WIDTHOF_BYTE )) & ((int)0xFF << (j* Machine.WIDTHOF_BYTE ) );
}
return i;
}
/**
* @param barr TODO
* @param start TODO
* @since VCafe 3.0
*/
public static final int constructInt( byte[] barr, int start )
{
int j;
int k;
int i = 0;
for ( k = 0, j = Machine.SIZEOF_INT - 1; j > -1; j--, k++ )
{
// i |= barr[ start + j ] << (j*Machine.WIDTHOF_BYTE);
/*
The int mask, ((int)0xFF << (j* Machine.WIDTHOF_BYTE ), is needed because
Java does sign aware widening. So something like (byte)0x80 widens to
0xFF80. Of course this screws things up when you try to OR into i the shifted
byte.
*/
i |= ( barr[ start + k ] << (j* Machine.WIDTHOF_BYTE )) & ((int)0xFF << (j* Machine.WIDTHOF_BYTE ) );
}
return i;
}
/**
* @param i TODO
* @since VCafe 3.0
*/
public static final byte[] deconstructInt( int i )
{
byte[] barr = new byte[ Machine.SIZEOF_INT ];
for ( int k = 0, j = Machine.SIZEOF_INT - 1; j > -1; j--, k++ )
{
barr[ k ] = ( (byte)( i >> (j*Machine.WIDTHOF_BYTE) ) ) ;
}
return barr;
}
/**
* @param i TODO
* @param dest TODO
* @param index TODO
* @since VCafe 3.0
*/
public static final void deconstructIntInto( int i, byte[] dest, int index )
{
for ( int k = 0, j = Machine.SIZEOF_INT - 1; j > -1; j--, k++ )
{
dest[ index + k ] = ( (byte)( i >> (j*Machine.WIDTHOF_BYTE) ) ) ;
}
}
/**
* @param barr TODO
* @param start TODO
* @since VCafe 3.0
*/
/* long operations */
public static final long constructLong( int[] barr, int start )
{
int j;
int i;
long l = 0;
for ( i = 0, j = Machine.SIZEOF_LONG - 1; j > -1; j--, i++ )
{
// l |= barr[ start + j ] << (j*Machine.WIDTHOF_BYTE);
/*
The int mask, ((int)0xFF << (j* Machine.WIDTHOF_BYTE ), is needed because
Java does sign aware widening. So something like (byte)0x80 widens to
0xFF80. Of course this screws things up when you try to OR into l, that's lower case L, the shifted
byte.
*/
l |= ( barr[ start + i ] << (j* Machine.WIDTHOF_BYTE )) & ((long)0xFF << (j* Machine.WIDTHOF_BYTE ) );
}
return l;
}
/**
* @param barr TODO
* @param start TODO
* @since VCafe 3.0
*/
public static final long constructLong( byte[] barr, int start )
{
int j;
int i;
long l = 0;
for ( i = 0, j = Machine.SIZEOF_LONG - 1; j > -1; j--, i++ )
{
// l |= barr[ start + j ] << (j*Machine.WIDTHOF_BYTE);
/*
The int mask, ((int)0xFF << (j* Machine.WIDTHOF_BYTE ), is needed because
Java does sign aware widening. So something like (byte)0x80 widens to
0xFF80. Of course this screws things up when you try to OR into l, that's lower case L, the shifted
byte.
*/
l |= ( barr[ start + i ] << (j* Machine.WIDTHOF_BYTE )) & ((long)0xFF << (j* Machine.WIDTHOF_BYTE ) );
}
return l;
}
/**
* @param l TODO
* @since VCafe 3.0
*/
public static final byte[] deconstructLong( long l )
{
byte[] barr = new byte[ Machine.SIZEOF_LONG ];
for ( int i = 0, j = Machine.SIZEOF_LONG - 1; j > -1; j--, i++ )
{
barr[ i ] = ( (byte)( l >> (j*Machine.WIDTHOF_BYTE) ) ) ;
}
return barr;
}
/**
* @param l TODO
* @param dest TODO
* @param index TODO
* @since VCafe 3.0
*/
public static final void deconstructLongInto( long l, byte[] dest, int index )
{
for ( int i = 0, j = Machine.SIZEOF_LONG - 1; j > -1; j--, i++ )
{
dest[ index + i ] = ( (byte)( l >> (j*Machine.WIDTHOF_BYTE) ) ) ;
}
}
/**
* @param barr TODO
* @param start TODO
* @since VCafe 3.0
*/
/* InetAddress operations */
public static final String constructInetAddressString( byte[] barr, int start )
{
String ret =
(
((int)barr[ start ] & 0xFF ) + "." +
((int)barr[ start + 1 ] & 0xFF ) + "." +
((int)barr[ start + 2 ] & 0xFF ) + "." +
((int)barr[ start + 3 ] & 0xFF )
);
return ret;
}
}