Java Code Examples for java.io.DataInputStream#readFloat()

The following examples show how to use java.io.DataInputStream#readFloat() . 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: Vectors.java    From word2vec-query-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize a Vectors instance from an open input stream. This method closes the stream.
 * 
 * @param is
 *            the open stream
 * @throws IOException
 *             if there are problems reading from the stream
 */
public Vectors(InputStream is) throws IOException {
    DataInputStream dis = new DataInputStream(is);

    int words = dis.readInt();
    int size = dis.readInt();
    this.size = size;

    this.vectors = new float[words][];
    this.vocabVects = new String[words];

    for (int i = 0; i < words; i++) {
        this.vocabVects[i] = dis.readUTF();
        float[] vector = new float[size];
        for (int j = 0; j < size; j++)
            vector[j] = dis.readFloat();
        this.vectors[i] = vector;
    }
    this.vocab = new HashMap<String, Integer>();
    for (int i = 0; i < vocabVects.length; i++)
        vocab.put(vocabVects[i], i);
    dis.close();
}
 
Example 2
Source File: LocalScreen.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
public static boolean initialize(Alite alite, final DataInputStream dis) {
	LocalScreen ls = new LocalScreen(alite);
	try {
		ls.zoomFactor = dis.readFloat();
		ls.centerX = dis.readInt();
		ls.centerY = dis.readInt();
		ls.pendingZoomFactor = ls.zoomFactor;
		ls.pendingCenterX    = ls.centerX;
		ls.pendingCenterY    = ls.centerY;
	} catch (Exception e) {
		AliteLog.e("Local Screen Initialize", "Error in initializer.", e);
		return false;
	}
	alite.setScreen(ls);
	return true;
}
 
Example 3
Source File: AbstractBackedByteData.java    From cfr with MIT License 5 votes vote down vote up
@Override
public float getFloatAt(long o) throws ConfusedCFRException {
    DataInputStream dis = rawDataAsStream((int) o, 8);
    try {
        return dis.readFloat();
    } catch (Exception e) {
        throw new ConfusedCFRException(e);
    }
}
 
Example 4
Source File: DocumentCacheFile.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
void loadManualCropping(final DataInputStream in, final boolean docPage, final boolean leftPage)
        throws IOException {

    final int index = in.readShort();
    final SparseArrayEx<PageInfo> target = getPages(docPage, leftPage);
    PageInfo pageInfo = target.get(index, null);
    if (pageInfo == null) {
        pageInfo = new PageInfo(index);
        target.append(index, pageInfo);
    }
    pageInfo.manualCropping = new RectF(in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());

}
 
Example 5
Source File: Table.java    From QNotified with GNU General Public License v3.0 5 votes vote down vote up
public static Object readTypeAndObj(DataInputStream in) throws IOException {
    byte rtype = in.readByte();
    switch (rtype) {
        case TYPE_VOID:
            return null;
        case TYPE_BYTE:
            return (byte) in.read();
        case TYPE_BOOL:
            return in.read() != 0;
        case TYPE_WCHAR32:
            return in.readInt();
        case TYPE_INT:
            return in.readInt();
        case TYPE_SHORT:
            return in.readShort();
        case TYPE_LONG:
            return in.readLong();
        case TYPE_FLOAT:
            return in.readFloat();
        case TYPE_DOUBLE:
            return in.readDouble();
        case TYPE_IUTF8:
            return readIStr(in);
        case TYPE_IRAW:
            return readIRaw(in);
        case TYPE_TABLE:
            return readTable(in);
        case TYPE_ARRAY:
            return readArray(in);
        case TYPE_EOF:
            throw new IOException("Unexpected type: TYPE_EOF");
        default:
            throw new IOException("Unexpected type:" + rtype + "\"");
    }
}
 
Example 6
Source File: DocumentCacheFile.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
void loadAutoCropping(final DataInputStream in, final boolean docPage, final boolean leftPage)
        throws IOException {
    final int index = in.readShort();
    final SparseArrayEx<PageInfo> target = getPages(docPage, leftPage);
    PageInfo pageInfo = target.get(index, null);
    if (pageInfo == null) {
        pageInfo = new PageInfo(index);
        target.append(index, pageInfo);
    }
    pageInfo.autoCropping = new RectF(in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
}
 
Example 7
Source File: PacketWrapper.java    From HexxitGear with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static Object readObjectFromStream(DataInputStream data, Class curClass) throws IOException
{
    if (curClass.equals(Boolean.class))
    {
        return data.readBoolean();
    }
    else if (curClass.equals(Byte.class))
    {
        return data.readByte();
    }
    else if (curClass.equals(Integer.class))
    {
        return data.readInt();
    }
    else if (curClass.equals(String.class))
    {
        return data.readUTF();
    }
    else if (curClass.equals(Double.class))
    {
        return data.readDouble();
    }
    else if (curClass.equals(Float.class))
    {
        return data.readFloat();
    }
    else if (curClass.equals(Long.class))
    {
        return data.readLong();
    }
    else if (curClass.equals(Short.class))
    {
        return data.readShort();
    }

    return null;
}
 
Example 8
Source File: HyperspaceScreen.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public static HyperspaceScreen createScreen(Alite alite, DataInputStream dis) throws IOException {
	boolean intergal = dis.readBoolean();
	HyperspaceScreen hs = new HyperspaceScreen(alite, intergal);
	hs.counter = dis.readFloat();
	hs.red = dis.readFloat();
	hs.green = dis.readFloat();
	hs.blue = dis.readFloat();
	hs.increase = dis.readInt();
	hs.restartedSound = dis.readBoolean();
	hs.screenLoad = true;
	return hs;
}
 
Example 9
Source File: IonoGalileo.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
@Override
public void read(DataInputStream dai, boolean oldVersion) throws IOException {
	int v=1;
	if(!oldVersion) v=dai.readInt();

	if(v==1){

		health = dai.readLong();
		utcA1 = dai.readDouble();
		utcA0 = dai.readDouble();
		utcTOW = dai.readLong();
		utcWNT = dai.readInt();
		utcLS = dai.readInt();
		utcWNF = dai.readInt();
		utcDN = dai.readInt();
		utcLSF = dai.readInt();
		for(int i=0;i<alpha.length;i++){
			alpha[i] = dai.readFloat();
		}
		for(int i=0;i<beta.length;i++){
			beta[i] = dai.readFloat();
		}
		validHealth = dai.readBoolean();
		validUTC = dai.readBoolean();
		validKlobuchar = dai.readBoolean();
		long l = dai.readLong();
		refTime = new Time(l>0?l:System.currentTimeMillis());
	}else{
		throw new IOException("Unknown format version:"+v);
	}
}
 
Example 10
Source File: IonoGps.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
@Override
public void read(DataInputStream dai, boolean oldVersion) throws IOException {
	int v=1;
	if(!oldVersion) v=dai.readInt();

	if(v==1){

		health = dai.readLong();
		utcA1 = dai.readDouble();
		utcA0 = dai.readDouble();
		utcTOW = dai.readLong();
		utcWNT = dai.readInt();
		utcLS = dai.readInt();
		utcWNF = dai.readInt();
		utcDN = dai.readInt();
		utcLSF = dai.readInt();
		for(int i=0;i<alpha.length;i++){
			alpha[i] = dai.readFloat();
		}
		for(int i=0;i<beta.length;i++){
			beta[i] = dai.readFloat();
		}
		validHealth = dai.readBoolean();
		validUTC = dai.readBoolean();
		validKlobuchar = dai.readBoolean();
		long l = dai.readLong();
		refTime = new Time(l>0?l:System.currentTimeMillis());
	}else{
		throw new IOException("Unknown format version:"+v);
	}
}
 
Example 11
Source File: LivenessMemoryResultsSnapshot.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void readFromStream(DataInputStream in) throws IOException {
    super.readFromStream(in);

    int len = in.readInt();
    nTrackedAllocObjects = new long[len];

    for (int i = 0; i < len; i++) {
        nTrackedAllocObjects[i] = in.readLong();
    }

    len = in.readInt();
    nTrackedLiveObjects = new int[len];

    for (int i = 0; i < len; i++) {
        nTrackedLiveObjects[i] = in.readInt();
    }

    len = in.readInt();
    maxSurvGen = new int[len];

    for (int i = 0; i < len; i++) {
        maxSurvGen[i] = in.readInt();
    }

    len = in.readInt();
    trackedLiveObjectsSize = new long[len];

    for (int i = 0; i < len; i++) {
        trackedLiveObjectsSize[i] = in.readLong();
    }

    len = in.readInt();
    avgObjectAge = new float[len];

    for (int i = 0; i < len; i++) {
        avgObjectAge[i] = in.readFloat();
    }

    nInstrClasses = in.readInt();

    len = in.readInt();
    nTotalAllocObjects = new int[len];

    for (int i = 0; i < len; i++) {
        nTotalAllocObjects[i] = in.readInt();
    }

    nTrackedItems = in.readInt();
    maxValue = in.readLong();
    nTotalTrackedBytes = in.readLong();
    nTotalTracked = in.readInt();
    currentEpoch = in.readInt();
}
 
Example 12
Source File: ConvertVectors.java    From word2vec-query-expansion with Apache License 2.0 4 votes vote down vote up
/**
 * @param args
 *            the input C vectors file, output Java vectors file
 */
public static void main(String[] args) throws VectorsException, IOException {
    float[][] vectors;
    String[] vocabVects;
    int words;
    int size;

    File vectorFile = new File(args[0]);
    File outputFile = new File(args[1]);

    double len;

    if (!vectorFile.exists())
        throw new VectorsException("Vectors file not found");

    FileInputStream fis = new FileInputStream(vectorFile);

    StringBuilder sb = new StringBuilder();
    char ch = (char) fis.read();
    while (ch != '\n') {
        sb.append(ch);
        ch = (char) fis.read();
    }

    String line = sb.toString();
    String[] parts = line.split("\\s+");
    words = (int) Long.parseLong(parts[0]);
    size = (int) Long.parseLong(parts[1]);
    vectors = new float[words][];
    vocabVects = new String[words];

    System.out.println("" + words + " words with size " + size + " per vector.");

    byte[] orig = new byte[4];
    byte[] buf = new byte[4];
    for (int w = 0; w < words; w++) {
        if (w % (words / 10) == 0) {
            System.out.println("Read " + w + " words");
        }

        sb.setLength(0);
        ch = (char) fis.read();
        while (!Character.isWhitespace(ch) && ch >= 0 && ch <= 256) {
            sb.append((char) ch);
            ch = (char) fis.read();
        }
        ch = (char) fis.read();
        String st = sb.toString();

        vocabVects[w] = st;
        float[] m = new float[size];
        for (int i = 0; i < size; i++) {
            // read a little endian floating point number and interpret it as a big endian one, see
            // http://stackoverflow.com/questions/2782725/converting-float-values-from-big-endian-to-little-endian/2782742#2782742
            // NB: this code assumes amd64 architecture
            for (int j = 0; j < 4; j++)
                orig[j] = (byte) fis.read();
            buf[2] = orig[0];
            buf[1] = orig[1];
            buf[0] = orig[2];
            buf[3] = orig[3];
            // this code can be made more efficient by reusing the ByteArrayInputStream
            DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf));
            m[i] = dis.readFloat();
            dis.close();
        }
        len = 0;
        for (int i = 0; i < size; i++)
            len += m[i] * m[i];
        len = (float) Math.sqrt(len);
        for (int i = 0; i < size; i++)
            m[i] /= len;
        vectors[w] = m;
    }
    fis.close();

    FileOutputStream fos = new FileOutputStream(outputFile);
    Vectors instance = new Vectors(vectors, vocabVects);
    instance.writeTo(fos);
}
 
Example 13
Source File: BinaryConstantPool.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 */
BinaryConstantPool(DataInputStream in) throws IOException {
    // JVM 4.1 ClassFile.constant_pool_count
    types = new byte[in.readUnsignedShort()];
    cpool = new Object[types.length];
    for (int i = 1 ; i < cpool.length ; i++) {
        int j = i;
        // JVM 4.4 cp_info.tag
        switch(types[i] = in.readByte()) {
          case CONSTANT_UTF8:
            cpool[i] = in.readUTF();
            break;

          case CONSTANT_INTEGER:
            cpool[i] = new Integer(in.readInt());
            break;
          case CONSTANT_FLOAT:
            cpool[i] = new Float(in.readFloat());
            break;
          case CONSTANT_LONG:
            cpool[i++] = new Long(in.readLong());
            break;
          case CONSTANT_DOUBLE:
            cpool[i++] = new Double(in.readDouble());
            break;

          case CONSTANT_CLASS:
          case CONSTANT_STRING:
            // JVM 4.4.3 CONSTANT_String_info.string_index
            // or JVM 4.4.1 CONSTANT_Class_info.name_index
            cpool[i] = new Integer(in.readUnsignedShort());
            break;

          case CONSTANT_FIELD:
          case CONSTANT_METHOD:
          case CONSTANT_INTERFACEMETHOD:
          case CONSTANT_NAMEANDTYPE:
            // JVM 4.4.2 CONSTANT_*ref_info.class_index & name_and_type_index
            cpool[i] = new Integer((in.readUnsignedShort() << 16) | in.readUnsignedShort());
            break;

          case CONSTANT_METHODHANDLE:
            cpool[i] = readBytes(in, 3);
            break;
          case CONSTANT_METHODTYPE:
            cpool[i] = readBytes(in, 2);
            break;
          case CONSTANT_INVOKEDYNAMIC:
            cpool[i] = readBytes(in, 4);
            break;

          case 0:
          default:
            throw new ClassFormatError("invalid constant type: " + (int)types[i]);
        }
    }
}
 
Example 14
Source File: SelfDecompiler.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Parse the GOTO bytecode.
 */
public void parseQuotientByteCode(Vertex state, DataInputStream dataStream, Network network) throws IOException {
	float correctness = dataStream.readFloat();
	long id = dataStream.readLong();
	if (id == 0) {
		return;
	}
	Vertex element = network.findById(id);
	if (element == null) {
		return;
	}
	Relationship relationship = state.addWeakRelationship(Primitive.QUOTIENT, element, correctness);
	id = dataStream.readLong();
	if (id == 0) {
		return;
	}
	element = network.findById(id);
	if (element == null) {
		return;
	}
	if (element.is(Primitive.PREVIOUS)) {
		id = dataStream.readLong();
		Vertex meta = network.createTemporyVertex();
		relationship.setMeta(meta);
		while (id > 0) {
			element = network.findById(id);
			if (element != null) {
				if (element.is(Primitive.NOT)) {
					id = dataStream.readLong();
					if (id == 0) {
						return;
					}
					element = network.findById(id);
					if (element == null) {
						continue;
					}
					meta.removeRelationship(Primitive.PREVIOUS, element);
				} else {
					meta.addRelationship(Primitive.PREVIOUS, element);						
				}
			}
			id = dataStream.readLong();
		}
	}
}
 
Example 15
Source File: ArrayUtil.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static float[] readFloat(int length, DataInputStream dis) throws IOException {
    float[] ret = new float[length];
    for (int i = 0; i < length; i++)
        ret[i] = dis.readFloat();
    return ret;
}
 
Example 16
Source File: VivaldiPositionProvider.java    From TorrentEngine with GNU General Public License v3.0 4 votes vote down vote up
public DHTNetworkPosition
deserialisePosition(
	DataInputStream		is )

	throws IOException
{
	float[]	data = new float[4];
	
	for (int i=0;i<data.length;i++){
		
		data[i] = is.readFloat();
	}
	
	VivaldiPosition	pos = VivaldiPositionFactory.createPosition();
	
	pos.fromFloatArray( data );
	
	return( pos );
}
 
Example 17
Source File: BinaryConstantPool.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 */
BinaryConstantPool(DataInputStream in) throws IOException {
    // JVM 4.1 ClassFile.constant_pool_count
    types = new byte[in.readUnsignedShort()];
    cpool = new Object[types.length];
    for (int i = 1 ; i < cpool.length ; i++) {
        int j = i;
        // JVM 4.4 cp_info.tag
        switch(types[i] = in.readByte()) {
          case CONSTANT_UTF8:
            cpool[i] = in.readUTF();
            break;

          case CONSTANT_INTEGER:
            cpool[i] = new Integer(in.readInt());
            break;
          case CONSTANT_FLOAT:
            cpool[i] = new Float(in.readFloat());
            break;
          case CONSTANT_LONG:
            cpool[i++] = new Long(in.readLong());
            break;
          case CONSTANT_DOUBLE:
            cpool[i++] = new Double(in.readDouble());
            break;

          case CONSTANT_CLASS:
          case CONSTANT_STRING:
            // JVM 4.4.3 CONSTANT_String_info.string_index
            // or JVM 4.4.1 CONSTANT_Class_info.name_index
            cpool[i] = new Integer(in.readUnsignedShort());
            break;

          case CONSTANT_FIELD:
          case CONSTANT_METHOD:
          case CONSTANT_INTERFACEMETHOD:
          case CONSTANT_NAMEANDTYPE:
            // JVM 4.4.2 CONSTANT_*ref_info.class_index & name_and_type_index
            cpool[i] = new Integer((in.readUnsignedShort() << 16) | in.readUnsignedShort());
            break;

          case CONSTANT_METHODHANDLE:
            cpool[i] = readBytes(in, 3);
            break;
          case CONSTANT_METHODTYPE:
            cpool[i] = readBytes(in, 2);
            break;
          case CONSTANT_INVOKEDYNAMIC:
            cpool[i] = readBytes(in, 4);
            break;

          case 0:
          default:
            throw new ClassFormatError("invalid constant type: " + (int)types[i]);
        }
    }
}
 
Example 18
Source File: EditableResources.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
void loadSVGRatios(DataInputStream input) throws IOException {
    ratioW = input.readFloat();
    ratioH = input.readFloat();
}
 
Example 19
Source File: ConstPool.java    From HotswapAgent with GNU General Public License v2.0 4 votes vote down vote up
public FloatInfo(DataInputStream in, int index) throws IOException
{
    super(index);
    value = in.readFloat();
}
 
Example 20
Source File: Self4Decompiler.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Parse the GOTO bytecode.
 */
@Override
public void parseQuotientByteCode(Vertex state, DataInputStream dataStream, Network network) throws IOException {
	float correctness = dataStream.readFloat();
	long id = dataStream.readLong();
	if (id == 0) {
		return;
	}
	Object[] result = new Object[3];
	result[0] = id;
	parseArgumentByteCode(result, dataStream, null, network);
	id = (Long)result[0];
	Vertex element = (Vertex)result[2];
	if (element == null) {
		return;
	}
	Relationship relationship = state.addWeakRelationship(Primitive.QUOTIENT, element, correctness);
	if (id == 0) {
		return;
	}
	result[0] = id;
	result[1] = null;
	result[2] = null;
	parseArgumentByteCode(result, dataStream, null, network);
	id = (Long)result[0];
	element = (Vertex)result[2];
	if (element == null) {
		return;
	}
	if (element.is(Primitive.PREVIOUS)) {
		Vertex meta = network.createTemporyVertex();
		relationship.setMeta(meta);
		while (id > 0) {
			result[0] = id;
			result[1] = null;
			result[2] = null;
			parseArgumentByteCode(result, dataStream, null, network);
			id = (Long)result[0];
			element = (Vertex)result[2];
			if (element != null) {
				if (element.is(Primitive.NOT)) {
					if (id == 0) {
						return;
					}
					result[0] = id;
					result[1] = null;
					result[2] = null;
					parseArgumentByteCode(result, dataStream, null, network);
					id = (Long)result[0];
					element = (Vertex)result[2];
					if (element == null) {
						continue;
					}
					meta.removeRelationship(Primitive.PREVIOUS, element);
				} else {
					meta.addRelationship(Primitive.PREVIOUS, element);						
				}
			}
		}
	}
}