当前位置: 首页>>代码示例>>Java>>正文


Java EndianUtils类代码示例

本文整理汇总了Java中org.apache.commons.io.EndianUtils的典型用法代码示例。如果您正苦于以下问题:Java EndianUtils类的具体用法?Java EndianUtils怎么用?Java EndianUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EndianUtils类属于org.apache.commons.io包,在下文中一共展示了EndianUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readBlockMap

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
protected void readBlockMap() throws IOException {
	/*
	  Only need to read the block map at most once, it is
	  invariant.  On the rare occasions when we do write to the
	  virtualdisk, we update the block map in both local memory
	  and out to the file, so the two are always synchronized.
	*/
	if( blockMap != null )
		return;
	
	int N = (int)header.blockCount();
	blockMap = new int[N];
	RandomAccessFile raf = new RandomAccessFile( source, "r" );
	raf.seek( header.blocksOffset() );
	byte[] ba = new byte[4*N];
	raf.readFully( ba );
	raf.close();

	// LOOK: We are assuming little-endian formats, seems to hold...
	for( int i = 0; i < N; i++ ) {
		blockMap[i] = (int)EndianUtils.readSwappedUnsignedInteger
			( ba, 4*i );
	}
	checkBlockMap();
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:26,代码来源:VDIDisk.java

示例2: readFrom

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
static private UUID readFrom( byte[] ba, int offset ) {
	long timeLow = EndianUtils.readSwappedUnsignedInteger
		( ba, offset );
	int timeMidI = EndianUtils.readSwappedUnsignedShort
		( ba, offset + 4 );
	long timeMid = timeMidI & 0xffffffffL;
	int versionTimeHiI = EndianUtils.readSwappedUnsignedShort
		( ba, offset + 6 );
	long versionTimeHi = versionTimeHiI & 0xffffffffL;
	long msb = (timeLow << 32) | (timeMid << 16) | versionTimeHi;

	/*		int reservedClockSeqI = EndianUtils.readSwappedUnsignedShort
		( ba, offset + 10 );
	long reservedClockSeq = reservedClockSeqI & 0xffffffffL;
	*/
	long lsb = 0;
	for( int i = 0; i < 8; i++ )
		lsb |= (ba[offset+8+i] & 0xffL) << (56 - 8*i);
	return new UUID( msb, lsb );
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:21,代码来源:VDIHeaders.java

示例3: getSerialNumber

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public String getSerialNumber()
{
    int serial0 = EndianUtils.readSwappedInteger(mData, 8);
    int serial1 = EndianUtils.readSwappedInteger(mData, 12);
    int serial2 = EndianUtils.readSwappedInteger(mData, 16);
    int serial3 = EndianUtils.readSwappedInteger(mData, 20);

    StringBuilder sb = new StringBuilder();

    sb.append(String.format("%08X", serial0));
    sb.append("-");
    sb.append(String.format("%08X", serial1));
    sb.append("-");
    sb.append(String.format("%08X", serial2));
    sb.append("-");
    sb.append(String.format("%08X", serial3));

    return sb.toString();
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:20,代码来源:HackRFTunerController.java

示例4: decodeBitmap

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
private void decodeBitmap(String filename) throws IOException {
    System.out.println("Decoding " + filename);

    File inputFile = new File(filename);
    File outputFile = new File(outputDirectory + File.separator + FilenameUtils.removeExtension(inputFile.getName()));

    FileInputStream fis = new FileInputStream(filename);
    //skip 6 bytes
    fis.skip(6);
    //read the length we encoded
    int fileSize = EndianUtils.readSwappedInteger(fis);
    //skip the rest of the header
    fis.skip(44);
    Files.copy(fis, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    //truncate the file
    FileChannel outChan = new FileOutputStream(outputFile, true).getChannel();
    outChan.truncate(fileSize);
    outChan.close();

    //clean up
    if (isCleanUp()) {
        //delete the bitmap
        System.out.println("Deleting: " + inputFile);
        FileUtils.deleteQuietly(inputFile);
    }
}
 
开发者ID:tylerpitchford,项目名称:bitmap-all-the-things,代码行数:27,代码来源:BattEngine.java

示例5: writeBlockMap

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
protected void writeBlockMap() throws IOException {
	int N = (int)header.blockCount();
	byte[] ba = new byte[4*N];
	log.info( "Writing BlockMap for : " + source );
	for( int i = 0; i < N; i++ ) {
		EndianUtils.writeSwappedInteger( ba, 4*i, blockMap[i] );
	}
	RandomAccessFile raf = new RandomAccessFile( source, "rw" );
	raf.seek( header.blocksOffset() );
	raf.write( ba );
	raf.close();
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:13,代码来源:VDIDisk.java

示例6: PreHeader

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
PreHeader( DataInput di ) throws IOException {
	byte[] ba = new byte[SIZEOF];
	di.readFully( ba );
	sig = EndianUtils.readSwappedUnsignedInteger( ba, 64 );
	if( sig != VDI_IMAGE_SIGNATURE )
		/*
		  LOOK: really want to know the source file exhibiting
		  the error
		*/
		throw new VDIMissingSignatureException();
	version = EndianUtils.readSwappedUnsignedInteger( ba, 68 );
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:13,代码来源:VDIHeaders.java

示例7: RTUUID

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public RTUUID( byte[] ba ) throws IOException {
	u32TimeLow = EndianUtils.readSwappedUnsignedInteger( ba, 0 );
	u16TimeMid = EndianUtils.readSwappedUnsignedShort( ba, 4 );
	u16TimeHiAndVersion = EndianUtils.readSwappedUnsignedShort( ba, 6);
	u8ClockSeqHiAndReserved = ba[8] & 0xff;
	u8ClockSeqLow = ba[9] & 0xff;
	au8Node = new int[6];
	for( int i = 0; i < 6; i++ ) {
		au8Node[i] = ba[10+i] & 0xff;
	}
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:12,代码来源:VDIHeaders.java

示例8: GrainDirectory

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public GrainDirectory( byte[] raw ) {
	gdes = new long[raw.length/4];
	for( int i = 0; i < gdes.length; i++ ) {
		long gt = EndianUtils.readSwappedUnsignedInteger( raw, 4*i );
		gdes[i] = gt;
	}
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:8,代码来源:GrainDirectory.java

示例9: GrainTable

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public GrainTable( byte[] raw ) {
	if( raw.length != SIZEOF ) {
		throw new IllegalArgumentException
			( "GrainTable raw buffer length " +
			  raw.length + ", expected " + SIZEOF);
	}
	gtes = new long[512];
	for( int i = 0; i < gtes.length; i++ ) {
		long gte = EndianUtils.readSwappedUnsignedInteger( raw, 4*i );
		gtes[i] = gte;
	}
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:13,代码来源:GrainTable.java

示例10: readFrom

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
static GrainMarker readFrom( DataInput di ) throws IOException {
	long l = di.readLong();
	long lba = EndianUtils.swapLong( l );
	int i = di.readInt();
	int size = EndianUtils.swapInteger( i );
	return new GrainMarker( lba, size );
}
 
开发者ID:UW-APL-EIS,项目名称:vmvols-java,代码行数:8,代码来源:StreamOptimizedSparseExtent.java

示例11: determineAvailableSampleRates

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
/**
 * Queries the device for available sample rates.  Will always provide at
 * least the default 10 MHz sample rate.
 */
private void determineAvailableSampleRates()
    throws LibUsbException, UsbException
{
    mSampleRates.clear();

    //Get a count of available sample rates.  If we get an exception, then
    //we're using an older firmware revision and only the default 10 MHz
    //rate is supported
    try
    {
        byte[] rawCount = readArray(Command.GET_SAMPLE_RATES, 0, 0, 4);

        if(rawCount != null)
        {
            int count = EndianUtils.readSwappedInteger(rawCount, 0);

            byte[] rawRates = readArray(Command.GET_SAMPLE_RATES, 0,
                count, (count * 4));

            for(int x = 0; x < count; x++)
            {
                int rate = EndianUtils.readSwappedInteger(rawRates, (x * 4));

                mSampleRates.add(new AirspySampleRate(x, rate, formatSampleRate(rate)));
            }
        }
    }
    catch(LibUsbException e)
    {
        //Press on, nothing else to do here ..
    }

    if(mSampleRates.isEmpty())
    {
        mSampleRates.add(DEFAULT_SAMPLE_RATE);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:42,代码来源:AirspyTunerController.java

示例12: read

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public int read(Request request, int value, int index, int length)
    throws UsbException
{
    if(!(length == 1 || length == 2 || length == 4))
    {
        throw new IllegalArgumentException("invalid length [" + length +
            "] must be: byte=1, short=2, int=4 to read a primitive");
    }

    ByteBuffer buffer = readArray(request, value, index, length);

    byte[] data = new byte[buffer.capacity()];

    buffer.get(data);

    switch(data.length)
    {
        case 1:
            return data[0];
        case 2:
            return EndianUtils.readSwappedShort(data, 0);
        case 4:
            return EndianUtils.readSwappedInteger(data, 0);
        default:
            throw new UsbException("read() primitive returned an "
                + "unrecognized byte array " + Arrays.toString(data));
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:29,代码来源:HackRFTunerController.java

示例13: getPartID

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public String getPartID()
{
    int part0 = EndianUtils.readSwappedInteger(mData, 0);
    int part1 = EndianUtils.readSwappedInteger(mData, 4);

    StringBuilder sb = new StringBuilder();

    sb.append(String.format("%08X", part0));
    sb.append("-");
    sb.append(String.format("%08X", part1));

    return sb.toString();
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:14,代码来源:HackRFTunerController.java

示例14: determineAvailableSampleRates

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
/**
 * Queries the device for available sample rates.  Will always provide at
 * least the default 10 MHz sample rate.
 */
private void determineAvailableSampleRates() 
					throws LibUsbException, DeviceException
{
	mSampleRates.clear();
	
	mSampleRates.add( DEFAULT_SAMPLE_RATE );
	
	//Get a count of available sample rates.  If we get an exception, then
	//we're using an older firmware revision and only the default 10 MHz
	//rate is supported
	try
	{
		byte[] rawCount = readArray( Command.GET_SAMPLE_RATES, 0, 0, 4 );

		
		if( rawCount != null )
		{
			int count = EndianUtils.readSwappedInteger( rawCount, 0 );
			
			byte[] rawRates = readArray( Command.GET_SAMPLE_RATES, 0, 
					count, ( count * 4 ) );

			for( int x = 0; x < count; x++ )
			{
				int rate = EndianUtils.readSwappedInteger( rawRates, ( x * 4 ) );
				
				if( rate != DEFAULT_SAMPLE_RATE.getRate() )
				{
					mSampleRates.add( new AirspySampleRate( x, rate, 
							formatSampleRate( rate ) ) );
				}
			}
		}
	}
	catch( LibUsbException e )
	{
		//Press on, nothing else to do here ..
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:44,代码来源:AirspyDevice.java

示例15: read

import org.apache.commons.io.EndianUtils; //导入依赖的package包/类
public static DBFHeader read(final DataInputStream dataInput) throws IOException
{
    final DBFHeader header = new DBFHeader();

    header.signature = dataInput.readByte();                           /* 0     */
    header.year = dataInput.readByte();                                /* 1     */
    header.month = dataInput.readByte();                               /* 2     */
    header.day = dataInput.readByte();                                 /* 3     */
    header.numberOfRecords = EndianUtils.readSwappedInteger(dataInput); //DbfUtils.readLittleEndianInt(dataInput);  /* 4-7   */

    header.headerLength = EndianUtils.readSwappedShort(dataInput);//DbfUtils.readLittleEndianShort(dataInput);   /* 8-9   */
    header.recordLength = EndianUtils.readSwappedShort(dataInput);//DbfUtils.readLittleEndianShort(dataInput);   /* 10-11 */

    header.reserved1 = dataInput.readShort();//DbfUtils.readLittleEndianShort(dataInput);        /* 12-13 */
    header.incompleteTransaction = dataInput.readByte();               /* 14    */
    header.encryptionFlag = dataInput.readByte();                      /* 15    */
    header.freeRecordThread = dataInput.readInt();//DbfUtils.readLittleEndianInt(dataInput); /* 16-19 */
    header.reserved2 = dataInput.readInt();                              /* 20-23 */
    header.reserved3 = dataInput.readInt();                              /* 24-27 */
    header.mdxFlag = dataInput.readByte();                             /* 28    */
    header.languageDriver = dataInput.readByte();                      /* 29    */
    header.reserved4 = dataInput.readShort();//DbfUtils.readLittleEndianShort(dataInput);        /* 30-31 */

    header.fields = new ArrayList<DBFField>();
    DBFField field;
    while ((field = DBFField.read(dataInput)) != null)
    {
        header.fields.add(field);
    }
    header.numberOfFields = header.fields.size();
    return header;
}
 
开发者ID:mraad,项目名称:ibn-battuta,代码行数:33,代码来源:DBFHeader.java


注:本文中的org.apache.commons.io.EndianUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。