Java Code Examples for org.apache.commons.io.EndianUtils#readSwappedInteger()

The following examples show how to use org.apache.commons.io.EndianUtils#readSwappedInteger() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 );
}