Java Code Examples for java.io.DataOutputStream#writeFloat()

The following examples show how to use java.io.DataOutputStream#writeFloat() . 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: ProxyGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void write(DataOutputStream out) throws IOException {
    if (value instanceof String) {
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF((String) value);
    } else if (value instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(((Integer) value).intValue());
    } else if (value instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(((Float) value).floatValue());
    } else if (value instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(((Long) value).longValue());
    } else if (value instanceof Double) {
        out.writeDouble(CONSTANT_DOUBLE);
        out.writeDouble(((Double) value).doubleValue());
    } else {
        throw new InternalError("bogus value entry: " + value);
    }
}
 
Example 2
Source File: ProxyGenerator.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void write(DataOutputStream out) throws IOException {
    if (value instanceof String) {
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF((String) value);
    } else if (value instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(((Integer) value).intValue());
    } else if (value instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(((Float) value).floatValue());
    } else if (value instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(((Long) value).longValue());
    } else if (value instanceof Double) {
        out.writeDouble(CONSTANT_DOUBLE);
        out.writeDouble(((Double) value).doubleValue());
    } else {
        throw new InternalError("bogus value entry: " + value);
    }
}
 
Example 3
Source File: ProxyGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void write(DataOutputStream out) throws IOException {
    if (value instanceof String) {
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF((String) value);
    } else if (value instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(((Integer) value).intValue());
    } else if (value instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(((Float) value).floatValue());
    } else if (value instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(((Long) value).longValue());
    } else if (value instanceof Double) {
        out.writeDouble(CONSTANT_DOUBLE);
        out.writeDouble(((Double) value).doubleValue());
    } else {
        throw new InternalError("bogus value entry: " + value);
    }
}
 
Example 4
Source File: CtClassJavaProxyGenerator.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
public void write(DataOutputStream out) throws IOException {
    if (value instanceof String) {
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF((String) value);
    } else if (value instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(((Integer) value).intValue());
    } else if (value instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(((Float) value).floatValue());
    } else if (value instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(((Long) value).longValue());
    } else if (value instanceof Double) {
        out.writeDouble(CONSTANT_DOUBLE);
        out.writeDouble(((Double) value).doubleValue());
    } else {
        throw new InternalError("bogus value entry: " + value);
    }
}
 
Example 5
Source File: NumberConstantData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write the constant to the output stream
 */
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
    if (num instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(num.intValue());
    } else if (num instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(num.longValue());
    } else if (num instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(num.floatValue());
    } else if (num instanceof Double) {
        out.writeByte(CONSTANT_DOUBLE);
        out.writeDouble(num.doubleValue());
    }
}
 
Example 6
Source File: NumberConstantData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write the constant to the output stream
 */
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
    if (num instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(num.intValue());
    } else if (num instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(num.longValue());
    } else if (num instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(num.floatValue());
    } else if (num instanceof Double) {
        out.writeByte(CONSTANT_DOUBLE);
        out.writeDouble(num.doubleValue());
    }
}
 
Example 7
Source File: EightBitQuantizer.java    From joshua with Apache License 2.0 5 votes vote down vote up
@Override
public void writeState(DataOutputStream out) throws IOException {
  out.writeUTF(getKey());
  out.writeInt(buckets.length);
  for (float bucket : buckets)
    out.writeFloat(bucket);
}
 
Example 8
Source File: CudaFloatDataBuffer.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] asBytes() {
    float[] data = asFloat();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    for (int i = 0; i < data.length; i++)
        try {
            dos.writeFloat(data[i]);
        } catch (IOException e) {
            e.printStackTrace();
        }
    return bos.toByteArray();
}
 
Example 9
Source File: IonoGps.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
@Override
public int write(DataOutputStream dos) throws IOException {
	int size=5;
	dos.writeUTF(MESSAGE_IONO); // 5
	dos.writeInt(STREAM_V); size +=4;
	dos.writeLong(health); size +=8;
	dos.writeDouble(utcA1); size +=8;
	dos.writeDouble(utcA0); size +=8;
	dos.writeLong(utcTOW); size +=8;
	dos.writeInt(utcWNT); size +=4;
	dos.writeInt(utcLS); size +=4;
	dos.writeInt(utcWNF); size +=4;
	dos.writeInt(utcDN); size +=4;
	dos.writeInt(utcLSF); size +=4;
	for(int i=0;i<alpha.length;i++){
		dos.writeFloat(alpha[i]); size +=4;
	}
	for(int i=0;i<beta.length;i++){
		dos.writeFloat(beta[i]); size +=4;
	}
	dos.writeBoolean(validHealth);  size +=1;
	dos.writeBoolean(validUTC); size +=1;
	dos.writeBoolean(validKlobuchar); size +=1;
	dos.writeLong(refTime==null?-1:refTime.getMsec());  size +=8;

	return size;
}
 
Example 10
Source File: Vectors.java    From word2vec-query-expansion with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this vector to an open output stream. This method closes the stream.
 * 
 * @param os
 *            the stream to write to
 * @throws IOException
 *             if there are problems writing to the stream
 */
public void writeTo(OutputStream os) throws IOException {
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeInt(this.vectors.length);
    dos.writeInt(this.size);

    for (int i = 0; i < vectors.length; i++) {
        dos.writeUTF(this.vocabVects[i]);
        for (int j = 0; j < size; j++)
            dos.writeFloat(this.vectors[i][j]);
    }
    dos.close();
}
 
Example 11
Source File: EditableResources.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void saveSVG(DataOutputStream out, Image i, boolean isMultiImage) throws IOException {
    SVG s = (SVG)i.getSVGDocument();
    out.writeInt(s.getSvgData().length);
    out.write(s.getSvgData());
    if(s.getBaseURL() == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(s.getBaseURL());
    }

    // unknown???
    out.writeBoolean(true);

    if(ignorePNGMode) {
        out.writeFloat(s.getRatioW());
        out.writeFloat(s.getRatioH());
        out.writeInt(0);
    } else {
        if(isMultiImage) {
            writeMultiImage(out, svgToMulti(i));
        } else {
            out.writeFloat(s.getRatioW());
            out.writeFloat(s.getRatioH());
            writeImageAsPNG(i, BufferedImage.TYPE_INT_ARGB, out);
        }
    }
}
 
Example 12
Source File: HyperspaceScreen.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveScreenState(DataOutputStream dos) throws IOException {
	dos.writeBoolean(intergal);
	dos.writeFloat(counter);
	dos.writeFloat(red);
	dos.writeFloat(green);
	dos.writeFloat(blue);
	dos.writeInt(increase);
	dos.writeBoolean(restartedSound);
}
 
Example 13
Source File: CudaFloatDataBuffer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] asBytes() {
    float[] data = asFloat();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    for (int i = 0; i < data.length; i++)
        try {
            dos.writeFloat(data[i]);
        } catch (IOException e) {
            log.error("",e);
        }
    return bos.toByteArray();
}
 
Example 14
Source File: DocumentCacheFile.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
void saveCropping(final DataOutputStream out, final int tag, final int index, final RectF cropping)
        throws IOException {
    out.writeByte(tag);
    out.writeShort(index);
    out.writeFloat(cropping.left);
    out.writeFloat(cropping.top);
    out.writeFloat(cropping.right);
    out.writeFloat(cropping.bottom);
}
 
Example 15
Source File: BinaryConstantPool.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write out the contents of the constant pool, including any additions
 * that have been added.
 */
public void write(DataOutputStream out, Environment env) throws IOException {
    int length = cpool.length;
    if (MoreStuff != null)
        length += MoreStuff.size();
    out.writeShort(length);
    for (int i = 1 ; i < cpool.length; i++) {
        int type = types[i];
        Object x = cpool[i];
        out.writeByte(type);
        switch (type) {
            case CONSTANT_UTF8:
                out.writeUTF((String) x);
                break;
            case CONSTANT_INTEGER:
                out.writeInt(((Number)x).intValue());
                break;
            case CONSTANT_FLOAT:
                out.writeFloat(((Number)x).floatValue());
                break;
            case CONSTANT_LONG:
                out.writeLong(((Number)x).longValue());
                i++;
                break;
            case CONSTANT_DOUBLE:
                out.writeDouble(((Number)x).doubleValue());
                i++;
                break;
            case CONSTANT_CLASS:
            case CONSTANT_STRING:
                out.writeShort(((Number)x).intValue());
                break;
            case CONSTANT_FIELD:
            case CONSTANT_METHOD:
            case CONSTANT_INTERFACEMETHOD:
            case CONSTANT_NAMEANDTYPE: {
                int value = ((Number)x).intValue();
                out.writeShort(value >> 16);
                out.writeShort(value & 0xFFFF);
                break;
            }
            case CONSTANT_METHODHANDLE:
            case CONSTANT_METHODTYPE:
            case CONSTANT_INVOKEDYNAMIC:
                out.write((byte[])x, 0, ((byte[])x).length);
                break;
            default:
                 throw new ClassFormatError("invalid constant type: "
                                               + (int)types[i]);
        }
    }
    for (int i = cpool.length; i < length; i++) {
        String string = (String)(MoreStuff.elementAt(i - cpool.length));
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF(string);
    }
}
 
Example 16
Source File: PeakListSaveHandler.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Add the peaks information into the XML document
 * 
 * @param peak
 * @param element
 * @param dataFileID
 * @throws IOException
 */
private void fillPeakElement(Feature peak, TransformerHandler hd)
    throws SAXException, IOException {
  AttributesImpl atts = new AttributesImpl();

  // <REPRESENTATIVE_SCAN>
  hd.startElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getRepresentativeScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getRepresentativeScanNumber()).length());
  hd.endElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName());

  // <FRAGMENT_SCAN>
  hd.startElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName(), atts);
  hd.characters(String.valueOf(peak.getMostIntenseFragmentScanNumber()).toCharArray(), 0,
      String.valueOf(peak.getMostIntenseFragmentScanNumber()).length());
  hd.endElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName());

  // <ALL_MS2_FRAGMENT_SCANS>
  fillAllMS2FragmentScanNumbers(peak.getAllMS2FragmentScanNumbers(), hd);

  int scanNumbers[] = peak.getScanNumbers();

  // <ISOTOPE_PATTERN>
  IsotopePattern isotopePattern = peak.getIsotopePattern();
  if (isotopePattern != null) {
    atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA",
        String.valueOf(isotopePattern.getStatus()));
    atts.addAttribute("", "", PeakListElementName.DESCRIPTION.getElementName(), "CDATA",
        isotopePattern.getDescription());
    hd.startElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName(), atts);
    atts.clear();

    fillIsotopePatternElement(isotopePattern, hd);

    hd.endElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName());

  }

  // <MZPEAK>
  atts.addAttribute("", "", PeakListElementName.QUANTITY.getElementName(), "CDATA",
      String.valueOf(scanNumbers.length));
  hd.startElement("", "", PeakListElementName.MZPEAKS.getElementName(), atts);
  atts.clear();

  // <SCAN_ID> <MASS> <HEIGHT>
  ByteArrayOutputStream byteScanStream = new ByteArrayOutputStream();
  DataOutputStream dataScanStream = new DataOutputStream(byteScanStream);

  ByteArrayOutputStream byteMassStream = new ByteArrayOutputStream();
  DataOutputStream dataMassStream = new DataOutputStream(byteMassStream);

  ByteArrayOutputStream byteHeightStream = new ByteArrayOutputStream();
  DataOutputStream dataHeightStream = new DataOutputStream(byteHeightStream);

  float mass, height;
  for (int scan : scanNumbers) {
    dataScanStream.writeInt(scan);
    dataScanStream.flush();
    DataPoint mzPeak = peak.getDataPoint(scan);
    if (mzPeak != null) {
      mass = (float) mzPeak.getMZ();
      height = (float) mzPeak.getIntensity();
    } else {
      mass = 0f;
      height = 0f;
    }
    dataMassStream.writeFloat(mass);
    dataMassStream.flush();
    dataHeightStream.writeFloat(height);
    dataHeightStream.flush();
  }

  byte[] bytes = Base64.encode(byteScanStream.toByteArray());
  hd.startElement("", "", PeakListElementName.SCAN_ID.getElementName(), atts);
  String sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.SCAN_ID.getElementName());

  bytes = Base64.encode(byteMassStream.toByteArray());
  hd.startElement("", "", PeakListElementName.MZ.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.MZ.getElementName());

  bytes = Base64.encode(byteHeightStream.toByteArray());
  hd.startElement("", "", PeakListElementName.HEIGHT.getElementName(), atts);
  sbytes = new String(bytes);
  hd.characters(sbytes.toCharArray(), 0, sbytes.length());
  hd.endElement("", "", PeakListElementName.HEIGHT.getElementName());

  hd.endElement("", "", PeakListElementName.MZPEAKS.getElementName());
}
 
Example 17
Source File: SerializeUtils.java    From incubator-iotdb with Apache License 2.0 4 votes vote down vote up
public static void serializeBatchData(BatchData batchData, DataOutputStream outputStream) {
  try {
    int length = batchData.length();
    TSDataType dataType = batchData.getDataType();
    outputStream.writeInt(length);
    outputStream.write(dataType.ordinal());
    switch (dataType) {
      case BOOLEAN:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          outputStream.writeBoolean(batchData.getBooleanByIndex(i));
        }
        break;
      case DOUBLE:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          outputStream.writeDouble(batchData.getDoubleByIndex(i));
        }
        break;
      case FLOAT:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          outputStream.writeFloat(batchData.getFloatByIndex(i));
        }
        break;
      case TEXT:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          Binary binary = batchData.getBinaryByIndex(i);
          outputStream.writeInt(binary.getLength());
          outputStream.write(binary.getValues());
        }
        break;
      case INT64:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          outputStream.writeLong(batchData.getLongByIndex(i));
        }
        break;
      case INT32:
        for (int i = 0; i < length; i++) {
          outputStream.writeLong(batchData.getTimeByIndex(i));
          outputStream.writeInt(batchData.getIntByIndex(i));
        }
        break;
    }
  } catch (IOException ignored) {
    // ignored
  }
}
 
Example 18
Source File: BinaryConstantPool.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write out the contents of the constant pool, including any additions
 * that have been added.
 */
public void write(DataOutputStream out, Environment env) throws IOException {
    int length = cpool.length;
    if (MoreStuff != null)
        length += MoreStuff.size();
    out.writeShort(length);
    for (int i = 1 ; i < cpool.length; i++) {
        int type = types[i];
        Object x = cpool[i];
        out.writeByte(type);
        switch (type) {
            case CONSTANT_UTF8:
                out.writeUTF((String) x);
                break;
            case CONSTANT_INTEGER:
                out.writeInt(((Number)x).intValue());
                break;
            case CONSTANT_FLOAT:
                out.writeFloat(((Number)x).floatValue());
                break;
            case CONSTANT_LONG:
                out.writeLong(((Number)x).longValue());
                i++;
                break;
            case CONSTANT_DOUBLE:
                out.writeDouble(((Number)x).doubleValue());
                i++;
                break;
            case CONSTANT_CLASS:
            case CONSTANT_STRING:
                out.writeShort(((Number)x).intValue());
                break;
            case CONSTANT_FIELD:
            case CONSTANT_METHOD:
            case CONSTANT_INTERFACEMETHOD:
            case CONSTANT_NAMEANDTYPE: {
                int value = ((Number)x).intValue();
                out.writeShort(value >> 16);
                out.writeShort(value & 0xFFFF);
                break;
            }
            case CONSTANT_METHODHANDLE:
            case CONSTANT_METHODTYPE:
            case CONSTANT_INVOKEDYNAMIC:
                out.write((byte[])x, 0, ((byte[])x).length);
                break;
            default:
                 throw new ClassFormatError("invalid constant type: "
                                               + (int)types[i]);
        }
    }
    for (int i = cpool.length; i < length; i++) {
        String string = MoreStuff.elementAt(i - cpool.length);
        out.writeByte(CONSTANT_UTF8);
        out.writeUTF(string);
    }
}
 
Example 19
Source File: ConstantFloat.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Dump constant float to file stream in binary format.
 *
 * @param file Output file stream
 * @throws IOException
 */
@Override
public final void dump( final DataOutputStream file ) throws IOException {
    file.writeByte(super.getTag());
    file.writeFloat(bytes);
}
 
Example 20
Source File: PassFloatByReferenceBinary.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
public void writeWire(final DataOutputStream out) throws IOException {

      out.writeFloat(value);
   }