public void marshal(DataOutputStream dos) { try { dos.writeFloat((float) x); dos.writeFloat((float) y); dos.writeFloat((float) z); } // end try catch (Exception e) { System.out.println(e); } } // end of marshal method
@Override public byte[] asBytes() { if (allocationMode == AllocationMode.HEAP) { ByteArrayOutputStream bos = new ByteArrayOutputStream(getElementSize() * length()); DataOutputStream dos = new DataOutputStream(bos); if (dataType() == Type.DOUBLE) { if (doubleData == null) throw new IllegalStateException("Double array is null!"); try { for (int i = 0; i < doubleData.length; i++) dos.writeDouble(doubleData[i]); } catch (IOException e) { throw new RuntimeException(e); } } else { if (floatData == null) throw new IllegalStateException("Double array is null!"); try { for (int i = 0; i < floatData.length; i++) dos.writeFloat(floatData[i]); } catch (IOException e) { throw new RuntimeException(e); } } return bos.toByteArray(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); if (dataType() == Type.DOUBLE) { for (int i = 0; i < length(); i++) { try { dos.writeDouble(getDouble(i)); } catch (IOException e) { e.printStackTrace(); } } } else { for (int i = 0; i < length(); i++) { try { dos.writeFloat(getFloat(i)); } catch (IOException e) { e.printStackTrace(); } } } return bos.toByteArray(); } }
protected void write(DataOutputStream out) throws IOException { out.writeUTF(allocationMode.name()); out.writeInt(length()); out.writeUTF(dataType().name()); if (dataType() == Type.DOUBLE) { for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i)); } else { for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i)); } }
public static File getSparseBinarySVDLIBCFile() throws Exception { File f = File.createTempFile("unit-test", ".dat"); DataOutputStream pw = new DataOutputStream(new FileOutputStream(f)); pw.writeInt(3); pw.writeInt(3); pw.writeInt(6); pw.writeInt(2); pw.writeInt(0); pw.writeFloat(2.3f); pw.writeInt(2); pw.writeFloat(3.8f); pw.writeInt(1); pw.writeInt(1); pw.writeFloat(1.3f); pw.writeInt(3); pw.writeInt(0); pw.writeFloat(4.2f); pw.writeInt(1); pw.writeFloat(2.2f); pw.writeInt(2); pw.writeFloat(0.5f); pw.close(); return f; }
/** * Set float range filter. Only match records if attribute value is beetwen min and max * (inclusive). */ public void SetFilterFloatRange(String attribute, float min, float max, boolean exclude) throws SphinxException { myAssert(min <= max, "min must be less or equal to max"); try { writeNetUTF8(_filters, attribute); _filters.writeInt(SPH_FILTER_FLOATRANGE); _filters.writeFloat(min); _filters.writeFloat(max); _filters.writeInt(exclude ? 1 : 0); } catch (Exception e) { myAssert(false, "IOException: " + e.getMessage()); } _filterCount++; }
void storeConfig() { DataOutputStream out; try { out = new DataOutputStream(openFileOutput("wscnprefs", Context.MODE_PRIVATE)); out.writeByte(1); // version out.writeInt(ScanService.scanData.getFlags()); // operation flags; out.writeInt(ScanService.scanData.getStoredValues()); // number of currently stored values out.writeInt(ScanService.scanData.getUploadedCount()); out.writeInt(ScanService.scanData.getUploadedRank()); out.writeInt(0); // Open WLANs, no longer used out.writeInt(ScanService.scanData.getFreeHotspotWLANs()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrAccelX()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrAccelY()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrAccelZ()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrCoG()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrOrientY()); out.writeFloat(ScanService.scanData.getTelemetryData().getCorrOrientZ()); out.close(); } catch (IOException ioe) { ioe.printStackTrace(); } }
public void outputBinary(DataOutputStream dos) throws IOException { dos.writeUTF(id); dos.writeInt(values.size()); int i = 0, j = 0; while (i < values.size()) { for (j = i; j < values.size() && values.get(j) != null; j++) {} int count = j - i - 1; dos.writeInt(count); for (j = 1; j <= count && i + j < values.size(); j++) { dos.writeFloat(values.get(i + j)); } i = j + 1; } }
private static void writeWatchableObject( DataOutputStream par0DataOutputStream, WatchableObject par1WatchableObject) throws IOException { int i = (par1WatchableObject.getObjectType() << 5 | par1WatchableObject.getDataValueId() & 0x1f) & 0xff; par0DataOutputStream.writeByte(i); switch (par1WatchableObject.getObjectType()) { case 0: par0DataOutputStream.writeByte(((Byte) par1WatchableObject.getObject()).byteValue()); break; case 1: par0DataOutputStream.writeShort(((Short) par1WatchableObject.getObject()).shortValue()); break; case 2: par0DataOutputStream.writeInt(((Integer) par1WatchableObject.getObject()).intValue()); break; case 3: par0DataOutputStream.writeFloat(((Float) par1WatchableObject.getObject()).floatValue()); break; case 4: Packet.writeString((String) par1WatchableObject.getObject(), par0DataOutputStream); break; case 5: ItemStack itemstack = (ItemStack) par1WatchableObject.getObject(); par0DataOutputStream.writeShort(itemstack.getItem().shiftedIndex); par0DataOutputStream.writeByte(itemstack.stackSize); par0DataOutputStream.writeShort(itemstack.getItemDamage()); break; case 6: ChunkCoordinates chunkcoordinates = (ChunkCoordinates) par1WatchableObject.getObject(); par0DataOutputStream.writeInt(chunkcoordinates.posX); par0DataOutputStream.writeInt(chunkcoordinates.posY); par0DataOutputStream.writeInt(chunkcoordinates.posZ); break; } }
@SuppressWarnings("rawtypes") private static void writeObjectToStream(Object obj, DataOutputStream data) throws IOException { Class objClass = obj.getClass(); if (objClass.equals(Boolean.class)) { data.writeBoolean((Boolean) obj); } else if (objClass.equals(Byte.class)) { data.writeByte((Byte) obj); } else if (objClass.equals(Integer.class)) { data.writeInt((Integer) obj); } else if (objClass.equals(String.class)) { data.writeUTF((String) obj); } else if (objClass.equals(Double.class)) { data.writeDouble((Double) obj); } else if (objClass.equals(Float.class)) { data.writeFloat((Float) obj); } else if (objClass.equals(Long.class)) { data.writeLong((Long) obj); } else if (objClass.equals(Short.class)) { data.writeShort((Short) obj); } }
/** Add new query with current settings to current search request. */ public int AddQuery(String query, String index, String comment) throws SphinxException { ByteArrayOutputStream req = new ByteArrayOutputStream(); /* build request */ try { DataOutputStream out = new DataOutputStream(req); out.writeInt(_offset); out.writeInt(_limit); out.writeInt(_mode); out.writeInt(_ranker); if (_ranker == SPH_RANK_EXPR) { writeNetUTF8(out, _rankexpr); } out.writeInt(_sort); writeNetUTF8(out, _sortby); writeNetUTF8(out, query); int weightLen = _weights != null ? _weights.length : 0; out.writeInt(weightLen); if (_weights != null) { for (int i = 0; i < _weights.length; i++) out.writeInt(_weights[i]); } writeNetUTF8(out, index); out.writeInt(0); out.writeInt(_minId); out.writeInt(_maxId); /* filters */ out.writeInt(_filterCount); out.write(_rawFilters.toByteArray()); /* group-by, max matches, sort-by-group flag */ out.writeInt(_groupFunc); writeNetUTF8(out, _groupBy); out.writeInt(_maxMatches); writeNetUTF8(out, _groupSort); out.writeInt(_cutoff); out.writeInt(_retrycount); out.writeInt(_retrydelay); writeNetUTF8(out, _groupDistinct); /* anchor point */ if (_latitudeAttr == null || _latitudeAttr.length() == 0 || _longitudeAttr == null || _longitudeAttr.length() == 0) { out.writeInt(0); } else { out.writeInt(1); writeNetUTF8(out, _latitudeAttr); writeNetUTF8(out, _longitudeAttr); out.writeFloat(_latitude); out.writeFloat(_longitude); } /* per-index weights */ out.writeInt(_indexWeights.size()); for (Iterator e = _indexWeights.keySet().iterator(); e.hasNext(); ) { String indexName = (String) e.next(); Integer weight = (Integer) _indexWeights.get(indexName); writeNetUTF8(out, indexName); out.writeInt(weight.intValue()); } /* max query time */ out.writeInt(_maxQueryTime); /* per-field weights */ out.writeInt(_fieldWeights.size()); for (Iterator e = _fieldWeights.keySet().iterator(); e.hasNext(); ) { String field = (String) e.next(); Integer weight = (Integer) _fieldWeights.get(field); writeNetUTF8(out, field); out.writeInt(weight.intValue()); } /* comment */ writeNetUTF8(out, comment); /* overrides */ out.writeInt(_overrideTypes.size()); for (Iterator e = _overrideTypes.keySet().iterator(); e.hasNext(); ) { String attr = (String) e.next(); Integer type = (Integer) _overrideTypes.get(attr); Map values = (Map) _overrideValues.get(attr); writeNetUTF8(out, attr); out.writeInt(type.intValue()); out.writeInt(values.size()); for (Iterator e2 = values.keySet().iterator(); e2.hasNext(); ) { Long id = (Long) e2.next(); out.writeLong(id.longValue()); switch (type.intValue()) { case SPH_ATTR_FLOAT: out.writeFloat(((Float) values.get(id)).floatValue()); break; case SPH_ATTR_BIGINT: out.writeLong(((Long) values.get(id)).longValue()); break; default: out.writeInt(((Integer) values.get(id)).intValue()); break; } } } /* select-list */ writeNetUTF8(out, _select); /* done! */ out.flush(); int qIndex = _reqs.size(); _reqs.add(qIndex, req.toByteArray()); return qIndex; } catch (Exception e) { myAssert(false, "error in AddQuery(): " + e + ": " + e.getMessage()); } finally { try { _filters.close(); _rawFilters.close(); } catch (IOException e) { myAssert(false, "error in AddQuery(): " + e + ": " + e.getMessage()); } } return -1; }
public void writeBytes(OutputStream os) throws IOException { // Map between any modified UTF-8 and it's constant pool index. Map utf8ToIndex = new HashMap(); DataOutputStream dos = new DataOutputStream(os); TypeArray tags = getTags(); int len = (int) getLength(); int ci = 0; // constant pool index // collect all modified UTF-8 Strings from Constant Pool for (ci = 1; ci < len; ci++) { byte cpConstType = tags.getByteAt(ci); if (cpConstType == JVM_CONSTANT_Utf8) { Symbol sym = getSymbolAt(ci); utf8ToIndex.put(sym.asString(), new Short((short) ci)); } else if (cpConstType == JVM_CONSTANT_Long || cpConstType == JVM_CONSTANT_Double) { ci++; } } for (ci = 1; ci < len; ci++) { int cpConstType = (int) tags.getByteAt(ci); // write cp_info // write constant type switch (cpConstType) { case JVM_CONSTANT_Utf8: { dos.writeByte(cpConstType); Symbol sym = getSymbolAt(ci); dos.writeShort((short) sym.getLength()); dos.write(sym.asByteArray()); if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString()); break; } case JVM_CONSTANT_Unicode: throw new IllegalArgumentException("Unicode constant!"); case JVM_CONSTANT_Integer: dos.writeByte(cpConstType); dos.writeInt(getIntAt(ci)); if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci)); break; case JVM_CONSTANT_Float: dos.writeByte(cpConstType); dos.writeFloat(getFloatAt(ci)); if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci)); break; case JVM_CONSTANT_Long: { dos.writeByte(cpConstType); long l = getLongAt(ci); // long entries occupy two pool entries ci++; dos.writeLong(l); break; } case JVM_CONSTANT_Double: dos.writeByte(cpConstType); dos.writeDouble(getDoubleAt(ci)); // double entries occupy two pool entries ci++; break; case JVM_CONSTANT_Class: { dos.writeByte(cpConstType); // Klass already resolved. ConstantPool constains klassOop. Klass refKls = (Klass) getObjAt(ci); String klassName = refKls.getName().asString(); Short s = (Short) utf8ToIndex.get(klassName); dos.writeShort(s.shortValue()); if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); break; } // case JVM_CONSTANT_ClassIndex: case JVM_CONSTANT_UnresolvedClass: { dos.writeByte(JVM_CONSTANT_Class); String klassName = getSymbolAt(ci).asString(); Short s = (Short) utf8ToIndex.get(klassName); dos.writeShort(s.shortValue()); if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); break; } case JVM_CONSTANT_String: { dos.writeByte(cpConstType); String str = OopUtilities.stringOopToString(getObjAt(ci)); Short s = (Short) utf8ToIndex.get(str); dos.writeShort(s.shortValue()); if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); break; } // case JVM_CONSTANT_StringIndex: case JVM_CONSTANT_UnresolvedString: { dos.writeByte(JVM_CONSTANT_String); String val = getSymbolAt(ci).asString(); Short s = (Short) utf8ToIndex.get(val); dos.writeShort(s.shortValue()); if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); break; } // all external, internal method/field references case JVM_CONSTANT_Fieldref: case JVM_CONSTANT_Methodref: case JVM_CONSTANT_InterfaceMethodref: { dos.writeByte(cpConstType); int value = getIntAt(ci); short klassIndex = (short) extractLowShortFromInt(value); short nameAndTypeIndex = (short) extractHighShortFromInt(value); dos.writeShort(klassIndex); dos.writeShort(nameAndTypeIndex); if (DEBUG) debugMessage( "CP[" + ci + "] = ref klass = " + klassIndex + ", N&T = " + nameAndTypeIndex); break; } case JVM_CONSTANT_NameAndType: { dos.writeByte(cpConstType); int value = getIntAt(ci); short nameIndex = (short) extractLowShortFromInt(value); short signatureIndex = (short) extractHighShortFromInt(value); dos.writeShort(nameIndex); dos.writeShort(signatureIndex); if (DEBUG) debugMessage( "CP[" + ci + "] = N&T name = " + nameIndex + ", type = " + signatureIndex); break; } } // switch } dos.flush(); return; }