Java Code Examples for java.nio.MappedByteBuffer#getShort()

The following examples show how to use java.nio.MappedByteBuffer#getShort() . 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: Slopbucket.java    From jelectrum with MIT License 6 votes vote down vote up
public RecordEntry(long data_loc)
{
  int file = (int) (data_loc / SEGMENT_FILE_SIZE);
  MappedByteBuffer mbb = getBufferMap(file);
  int offset = (int) (data_loc % SEGMENT_FILE_SIZE);
  synchronized(mbb)
  {
    mbb.position(offset);
    max_data_size = mbb.getInt();

    int sz = mbb.getShort();
    byte[] b = new byte[sz];
    mbb.get(b);
    key = ByteString.copyFrom(b);

    sz = mbb.getInt();
    b = new byte[sz];
    mbb.get(b);
    value = ByteString.copyFrom(b);

  }
  this.data_loc = data_loc;
 
}
 
Example 2
Source File: DBase3FieldDescriptor.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Create a field descriptor from the current position of the binary stream.
 * @param byteBuffer ByteBuffer.
 */
public DBase3FieldDescriptor(MappedByteBuffer byteBuffer) {
    // Field name.
    byteBuffer.get(this.fieldName);

    // Field type.
    char dt = (char)byteBuffer.get();
    this.fieldType = DBaseDataType.valueOfDataType(dt);

    // Field address.
    byteBuffer.get(this.fieldAddress);

    // Length and scale.
    this.fieldLength = byteBuffer.get();
    this.fieldDecimalCount = byteBuffer.get();

    byteBuffer.getShort(); // reserved

    byteBuffer.get(this.dbasePlusLanReserved2);

    // Work area id.
    this.workAreaID = byteBuffer.get();

    byteBuffer.get(this.dbasePlusLanReserved3);

    // Fields.
    this.setFields = byteBuffer.get();

    byte[] data = new byte[6];
    byteBuffer.get(data); // reserved
}
 
Example 3
Source File: GeoWorldLoader.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("resource")
public static Map<String, Spatial> loadMeshs(String fileName) throws IOException {
	Map<String, Spatial> geoms = new HashMap<String, Spatial>();
	File geoFile = new File(fileName);
	FileChannel roChannel = null;
	MappedByteBuffer geo = null;
	roChannel = new RandomAccessFile(geoFile, "r").getChannel();
	int size = (int) roChannel.size();
	geo = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size).load();
	geo.order(ByteOrder.LITTLE_ENDIAN);
	while (geo.hasRemaining()) {
		short namelenght = geo.getShort();
		byte[] nameByte = new byte[namelenght];
		geo.get(nameByte);
		String name = new String(nameByte).intern();
		Node node = new Node(DEBUG ? name : null);
		byte intentions = 0;
		byte singleChildMaterialId = -1;
		int modelCount = geo.getShort();
		for (int c = 0; c < modelCount; c++) {
			Mesh m = new Mesh();

			int vectorCount = (geo.getInt()) * 3;
			ByteBuffer floatBuffer = ByteBuffer.allocateDirect(vectorCount * 4);
			FloatBuffer vertices = floatBuffer.asFloatBuffer();
			for (int x = 0; x < vectorCount; x++) {
				vertices.put(geo.getFloat());
			}

			int triangles = geo.getInt();
			ByteBuffer shortBuffer = ByteBuffer.allocateDirect(triangles * 2);
			ShortBuffer indexes = shortBuffer.asShortBuffer();
			for (int x = 0; x < triangles; x++) {
				indexes.put(geo.getShort());
			}

			Geometry geom = null;
			m.setCollisionFlags(geo.getShort());
			if ((m.getIntentions() & CollisionIntention.MOVEABLE.getId()) != 0) {
				// TODO: skip moveable collisions (ships, shugo boxes), not handled yet
				continue;
			}
			intentions |= m.getIntentions();
			m.setBuffer(VertexBuffer.Type.Position, 3, vertices);
			m.setBuffer(VertexBuffer.Type.Index, 3, indexes);
			m.createCollisionData();

			if ((intentions & CollisionIntention.DOOR.getId()) != 0 && (intentions & CollisionIntention.PHYSICAL.getId()) != 0) {
				if (!GeoDataConfig.GEO_DOORS_ENABLE) {
					continue;
				}
				geom = new DoorGeometry(name, m);
				// what if doors have few models ?
			}
			else {
				MaterialTemplate mtl = DataManager.MATERIAL_DATA.getTemplate(m.getMaterialId());
				geom = new Geometry(null, m);
				if (mtl != null || m.getMaterialId() == 11) {
					node.setName(name);
				}
				if (modelCount == 1) {
					geom.setName(name);
					singleChildMaterialId = geom.getMaterialId();
				}
				else {
					geom.setName(("child" + c + "_" + name).intern());
				}
				node.attachChild(geom);
			}
			geoms.put(geom.getName(), geom);
		}
		node.setCollisionFlags((short) (intentions << 8 | singleChildMaterialId & 0xFF));
		if (!node.getChildren().isEmpty()) {
			geoms.put(name, node);
		}
	}
	destroyDirectByteBuffer(geo);
	return geoms;

}