org.apache.commons.io.EndianUtils Java Examples

The following examples show how to use org.apache.commons.io.EndianUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DS1.java    From riiablo with Apache License 2.0 6 votes vote down vote up
private void readObjects(InputStream in) throws IOException {
  final int MAX_X = width  * DT1.Tile.SUBTILE_SIZE;
  final int MAX_Y = height * DT1.Tile.SUBTILE_SIZE;
  numObjects = version < 2 ? 0 : EndianUtils.readSwappedInteger(in);
  objects = numObjects == 0 ? Object.EMPTY_OBJECT_ARRAY : new Object[numObjects];
  for (int i = 0; i < numObjects; i++) {
    try {
      Object object = objects[i] = new Object().read(version, in);
      if (DEBUG_OBJECTS) Gdx.app.debug(TAG, object.toString());
      if (object.x < 0 || MAX_X <= object.x
       || object.y < 0 || MAX_Y <= object.y) {
        Gdx.app.error(TAG, "Object out of DS1 bounds: " + object);
      }
    } catch (Throwable t) {
      // Don't care, invalid object, skip it. Log it for posterity.
      Gdx.app.error(TAG, t.getMessage(), t);
    }
  }
}
 
Example #2
Source File: VorbisCommentReader.java    From AntennaPodSP with MIT License 5 votes vote down vote up
private VorbisCommentHeader readCommentHeader(InputStream input)
        throws IOException, VorbisCommentReaderException {
    try {
        long vendorLength = EndianUtils.readSwappedUnsignedInteger(input);
        String vendorName = readUTF8String(input, vendorLength);
        long userCommentLength = EndianUtils
                .readSwappedUnsignedInteger(input);
        return new VorbisCommentHeader(vendorName, userCommentLength);
    } catch (UnsupportedEncodingException e) {
        throw new VorbisCommentReaderException(e);
    }
}
 
Example #3
Source File: D2.java    From riiablo with Apache License 2.0 5 votes vote down vote up
Block(InputStream in) throws IOException {
  numEntries = EndianUtils.readSwappedInteger(in);
  entries = new Entry[numEntries];
  for (int i = 0; i < numEntries; i++) {
    entries[i] = new Entry(in);
    if (DEBUG_ENTRIES) Gdx.app.debug(TAG, entries[i].toString());
  }
}
 
Example #4
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
Path read(int version, Object[] objects, InputStream in) throws IOException {
  numPoints = EndianUtils.readSwappedInteger(in);
  points    = new Point[numPoints];
  x         = EndianUtils.readSwappedInteger(in);
  y         = EndianUtils.readSwappedInteger(in);

  Object object = null;
  for (int i = 0; i < objects.length; i++) {
    Object tmp = objects[i];
    if (tmp == null) continue;
    if (tmp.x != x || tmp.y != y) continue;
    if (object != null) Gdx.app.error(TAG, "More than one object is located at path position: " + this);
    object = tmp;
  }

  if (object == null) {
    Gdx.app.error(TAG, "No object associated with path: " + this);
    int skip = (version >= 15 ? 3 : 2) * Ints.BYTES;
    for (int p = 0; p < numPoints; p++) {
      in.skip(skip);
    }

    return this;
  }

  for (int p = 0; p < numPoints; p++) points[p] = new Point().read(version, in);
  object.path = this;
  return this;
}
 
Example #5
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
Group read(int version, InputStream in) throws IOException {
  if (in.available() >= Ints.BYTES) x      = EndianUtils.readSwappedInteger(in);
  if (in.available() >= Ints.BYTES) y      = EndianUtils.readSwappedInteger(in);
  if (in.available() >= Ints.BYTES) width  = EndianUtils.readSwappedInteger(in);
  if (in.available() >= Ints.BYTES) height = EndianUtils.readSwappedInteger(in);
  if (version >= 13) {
    if (in.available() >= Ints.BYTES) unk  = EndianUtils.readSwappedInteger(in);
  }
  return this;
}
 
Example #6
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
Object read(int version, InputStream in) throws IOException {
  type  = EndianUtils.readSwappedInteger(in);
  id    = EndianUtils.readSwappedInteger(in);
  x     = EndianUtils.readSwappedInteger(in);
  y     = EndianUtils.readSwappedInteger(in);
  flags = version < 6 ? 0 : EndianUtils.readSwappedInteger(in);
  path  = null;
  return this;
}
 
Example #7
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
Cell read(InputStream in, int orient) throws IOException {
  value       = EndianUtils.readSwappedInteger(in);
  mainIndex   = (short) ((value >>> MAIN_INDEX_OFFSET) & MAIN_INDEX_BITS);
  subIndex    = (short) ((value >>> SUB_INDEX_OFFSET)  & SUB_INDEX_BITS);
  orientation = (short) orient;
  return updateIndex();
}
 
Example #8
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void readPaths(InputStream in) throws IOException {
  if (version >= 14 && in.available() >= Ints.BYTES) {
    numPaths = EndianUtils.readSwappedInteger(in);
    paths = numPaths == 0 ? Path.EMPTY_PATH_ARRAY : new Path[numPaths];
    for (int i = 0; i < numPaths; i++) {
      Path path = paths[i] = new Path().read(version, objects, in);
      if (DEBUG_PATHS) Gdx.app.debug(TAG, path.toString());
    }
  } else {
    numPaths = 0;
    paths = Path.EMPTY_PATH_ARRAY;
  }
}
 
Example #9
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void readGroups(InputStream in) throws IOException {
  if (version >= 12 && (tagType == 1 || tagType == 2)) {
    if (version >= 18) IOUtils.skip(in, Ints.BYTES);
    numGroups = EndianUtils.readSwappedInteger(in);
    groups = numGroups == 0 ? Group.EMPTY_GROUP_ARRAY : new Group[numGroups];
    for (int i = 0; i < numGroups; i++) {
      groups[i] = new Group().read(version, in);
      if (DEBUG_GROUPS) Gdx.app.debug(TAG, groups[i].toString());
    }
  } else {
    numGroups = 0;
    groups = Group.EMPTY_GROUP_ARRAY;
  }
}
 
Example #10
Source File: DS1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private int readTags(InputStream in, int offset) throws IOException {
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      tags[offset] = EndianUtils.readSwappedInteger(in);
      offset += numTags;
    }
  }

  return offset;
}
 
Example #11
Source File: AirspyDevice.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 ..
	}
}
 
Example #12
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeShort(int v) throws IOException {
    EndianUtils.writeSwappedShort(stream, (short) v);
}
 
Example #13
Source File: DS1.java    From riiablo with Apache License 2.0 4 votes vote down vote up
Point read(int version, InputStream in) throws IOException {
  x      = EndianUtils.readSwappedInteger(in);
  y      = EndianUtils.readSwappedInteger(in);
  action = version < 15 ? 1 : EndianUtils.readSwappedInteger(in);
  return this;
}
 
Example #14
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeFloat(float v) throws IOException {
    EndianUtils.writeSwappedFloat(stream, v);
}
 
Example #15
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeLong(long v) throws IOException {
    EndianUtils.writeSwappedLong(stream, v);
}
 
Example #16
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeInt(int v) throws IOException {
    EndianUtils.writeSwappedInteger(stream, v);
}
 
Example #17
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeUnsignedShort(int num) throws IOException {
    EndianUtils.writeSwappedShort(stream, (short) num);
}
 
Example #18
Source File: LittleEndianInputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int readUnsignedShort() throws IOException {
    return EndianUtils.readSwappedUnsignedShort(this);
}
 
Example #19
Source File: LittleEndianInputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public short readShort() throws IOException {
    return EndianUtils.readSwappedShort(this);
}
 
Example #20
Source File: LittleEndianInputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public long readUnsignedInt() throws IOException {
    return EndianUtils.readSwappedUnsignedInteger(this);
}
 
Example #21
Source File: LittleEndianOutputStream.java    From FontVerter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeUnsignedInt(int num) throws IOException {
    EndianUtils.writeSwappedInteger(stream, num);
}
 
Example #22
Source File: SwappedDataInputStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedLong(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public long readLong()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedLong( in );
}
 
Example #23
Source File: SwappedDataInputStream.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}. 
 * @return the read long
 * @throws IOException if an I/O error occurs
 * @throws EOFException if an end of file is reached unexpectedly
 */
public float readFloat()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedFloat( in );
}
 
Example #24
Source File: SwappedDataInputStream.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public int readInt()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedInteger( in );
}
 
Example #25
Source File: SwappedDataInputStream.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedLong(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public long readLong()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedLong( in );
}
 
Example #26
Source File: SwappedDataInputStream.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedShort(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public short readShort()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedShort( in );
}
 
Example #27
Source File: SwappedDataInputStream.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public int readUnsignedShort()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedUnsignedShort( in );
}
 
Example #28
Source File: SwappedDataInputStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. 
 * @return the read long
 * @throws IOException if an I/O error occurs
 * @throws EOFException if an end of file is reached unexpectedly
 */
public double readDouble()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedDouble( in );
}
 
Example #29
Source File: SwappedDataInputStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}. 
 * @return the read long
 * @throws IOException if an I/O error occurs
 * @throws EOFException if an end of file is reached unexpectedly
 */
public float readFloat()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedFloat( in );
}
 
Example #30
Source File: SwappedDataInputStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}. 
 * @return the read long
 * @throws EOFException if an end of file is reached unexpectedly
 * @throws IOException if an I/O error occurs
 */
public int readInt()
    throws IOException, EOFException
{
    return EndianUtils.readSwappedInteger( in );
}