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

The following examples show how to use java.io.DataOutputStream#writeBoolean() . 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: Embedding.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void saveParameters(DataOutputStream os) throws IOException {
    os.writeByte(VERSION);
    saveInputShapes(os);
    os.writeBoolean(sparseGrad);
    os.writeUTF(dataType.toString());
    Set<Map.Entry<T, Integer>> embedderEntrySet = embedder.entrySet();
    os.writeInt(embedderEntrySet.size());
    for (Map.Entry<T, Integer> entry : embedderEntrySet) {
        byte[] encodedKey = encode(entry.getKey());
        os.writeInt(encodedKey.length);
        os.write(encodedKey);
        os.writeInt(embedder.get(entry.getKey()));
    }
    embedding.save(os);
}
 
Example 2
Source File: HprofHeap.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
void writeToStream(DataOutputStream out) throws IOException {
    out.writeUTF(SNAPSHOT_ID);
    out.writeInt(SNAPSHOT_VERSION);
    out.writeUTF(heapDumpFile.getAbsolutePath());
    out.writeLong(dumpBuffer.getTime());
    out.writeUTF(System.getProperty(OS_PROP));
    nearestGCRoot.writeToStream(out);
    allInstanceDumpBounds.writeToStream(out);
    heapDumpSegment.writeToStream(out);
    TagBounds.writeToStream(heapTagBounds, out);
    TagBounds.writeToStream(tagBounds, out);
    out.writeBoolean(instancesCountComputed);
    out.writeBoolean(referencesComputed);
    out.writeBoolean(retainedSizeComputed);
    out.writeBoolean(retainedSizeByClassComputed);
    out.writeInt(idMapSize);
    out.writeInt(segment);        
    idToOffsetMap.writeToStream(out);
    out.writeBoolean(domTree != null);
    if (domTree != null) {
        domTree.writeToStream(out);
    }
}
 
Example 3
Source File: NTRUSigningKeyGenerationParameters.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the parameter set to an output stream
 *
 * @param os an output stream
 * @throws java.io.IOException
 */
public void writeTo(OutputStream os)
    throws IOException
{
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeInt(N);
    dos.writeInt(q);
    dos.writeInt(d);
    dos.writeInt(d1);
    dos.writeInt(d2);
    dos.writeInt(d3);
    dos.writeInt(B);
    dos.writeInt(basisType);
    dos.writeDouble(beta);
    dos.writeDouble(normBound);
    dos.writeDouble(keyNormBound);
    dos.writeInt(signFailTolerance);
    dos.writeBoolean(primeCheck);
    dos.writeBoolean(sparse);
    dos.writeInt(bitsF);
    dos.write(keyGenAlg);
    dos.writeUTF(hashAlg.getAlgorithmName());
    dos.write(polyType);
}
 
Example 4
Source File: HprofHeap.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void writeToStream(DataOutputStream out) throws IOException {
    out.writeUTF(SNAPSHOT_ID);
    out.writeInt(SNAPSHOT_VERSION);
    out.writeUTF(heapDumpFile.getAbsolutePath());
    nearestGCRoot.writeToStream(out);
    allInstanceDumpBounds.writeToStream(out);
    heapDumpSegment.writeToStream(out);
    TagBounds.writeToStream(heapTagBounds, out);
    TagBounds.writeToStream(tagBounds, out);
    out.writeBoolean(instancesCountComputed);
    out.writeBoolean(referencesComputed);
    out.writeBoolean(retainedSizeComputed);
    out.writeBoolean(retainedSizeByClassComputed);
    out.writeInt(idMapSize);
    out.writeInt(segment);        
    idToOffsetMap.writeToStream(out);
    out.writeBoolean(domTree != null);
    if (domTree != null) {
        domTree.writeToStream(out);
    }
}
 
Example 5
Source File: WriteAheadRepositoryRecordSerde.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void serializeContentClaim(final ContentClaim claim, final long offset, final DataOutputStream out) throws IOException {
    if (claim == null) {
        out.write(0);
    } else {
        out.write(1);

        final ResourceClaim resourceClaim = claim.getResourceClaim();
        writeString(resourceClaim.getId(), out);
        writeString(resourceClaim.getContainer(), out);
        writeString(resourceClaim.getSection(), out);
        out.writeLong(claim.getOffset());
        out.writeLong(claim.getLength());

        out.writeLong(offset);
        out.writeBoolean(resourceClaim.isLossTolerant());
    }
}
 
Example 6
Source File: SetMaskChange.java    From Spade with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(DataOutputStream out) throws IOException
{
	out.writeInt(mask.length);
	for(int i = 0; i < mask.length; i++)
		out.writeBoolean(mask[i]);
}
 
Example 7
Source File: MemoryResultsSnapshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void writeToStream(DataOutputStream out) throws IOException {
    super.writeToStream(out);

    out.writeInt(nProfiledClasses);

    for (int i = 0; i < nProfiledClasses; i++) {
        out.writeUTF(classNames[i]);
        out.writeLong(objectsSizePerClass[i]);
    }

    out.writeBoolean(stacksForClasses != null);

    if (stacksForClasses != null) {
        out.writeInt(stacksForClasses.length);

        //.err.println("Stored len: " +stacksForClasses.length);
        for (int i = 0; i < stacksForClasses.length; i++) {
            if (stacksForClasses[i] == null) {
                //System.err.println("  [" + i + "] = 0");
                out.writeInt(0);
            } else {
                out.writeInt(stacksForClasses[i].getType());
                //System.err.println("  [" + i + "] = " + stacksForClasses[i].getType());
                stacksForClasses[i].writeToStream(out);
            }
        }

        out.writeBoolean(table != null);

        if (table != null) {
            table.writeToStream(out);
        }
    }
}
 
Example 8
Source File: StandardRecordWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected void writeNullableString(final DataOutputStream out, final String toWrite, String fieldName) throws IOException {
    if (toWrite == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        writeUTFLimited(out, toWrite, fieldName);
    }
}
 
Example 9
Source File: SerializerUtils.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void writeBinary(final DataOutputStream out, final Binary binary) throws IOException {

      if (binary == null) {
         out.writeBoolean(true);
      } else {
         out.writeBoolean(false);
         out.writeInt(binary.getWireableType());
         binary.writeWire(out);
      }
   }
 
Example 10
Source File: SerializedApplication.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void writeNullableString(DataOutputStream out, String string) throws IOException {
    if (string == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeUTF(string);
    }
}
 
Example 11
Source File: PlayerInfoPacket.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void serialize(DataOutputStream dos) throws IOException {
	dos.writeUTF(id);
	dos.writeUTF(name);
	dos.writeBoolean(ready);
	dos.writeBoolean(startFinished);
}
 
Example 12
Source File: PacketWrapper.java    From HexxitGear with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: SerializerUtils.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void writeIntArrayList(final DataOutputStream out, final IntArrayList list) throws IOException {

      if (list == null) {
         out.writeBoolean(true);
      } else {
         final int size = list.size();
         out.writeBoolean(false);
         out.writeInt(size);
         for (int i = 0; i < size; i++) {
            out.writeInt(list.get(i));
         }
      }
   }
 
Example 14
Source File: Message.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void writeWire(final DataOutputStream out) throws IOException {

      out.writeInt(type);
      out.writeBoolean(requiresSameCluster);
      SerializerUtils.writeTime(timestamp, out);
      SerializerUtils.writeUuid(clusterUUID, out);
      SerializerUtils.writeAddress(sender, out);
      SerializerUtils.writeReceiverAddress(receiver, out);
   }
 
Example 15
Source File: ValueMetaBaseTest.java    From hop with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadDataInet() throws Exception {
  InetAddress localhost = InetAddress.getByName( "127.0.0.1" );
  byte[] address = localhost.getAddress();
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  DataOutputStream dataOutputStream = new DataOutputStream( byteArrayOutputStream );
  dataOutputStream.writeBoolean( false );
  dataOutputStream.writeInt( address.length );
  dataOutputStream.write( address );

  DataInputStream dis = new DataInputStream( new ByteArrayInputStream( byteArrayOutputStream.toByteArray() ) );
  ValueMetaBase vm = new ValueMetaInternetAddress();
  assertEquals( localhost, vm.readData( dis ) );
}
 
Example 16
Source File: NetworkIdentitySet.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void writeToStream(DataOutputStream out) throws IOException {
    out.writeInt(VERSION_ADD_DEFAULT_NETWORK);
    out.writeInt(size());
    for (NetworkIdentity ident : this) {
        out.writeInt(ident.getType());
        out.writeInt(ident.getSubType());
        writeOptionalString(out, ident.getSubscriberId());
        writeOptionalString(out, ident.getNetworkId());
        out.writeBoolean(ident.getRoaming());
        out.writeBoolean(ident.getMetered());
        out.writeBoolean(ident.getDefaultNetwork());
    }
}
 
Example 17
Source File: TutAdvancedFlying.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void saveScreenState(DataOutputStream dos) throws IOException {
	if (mediaPlayer != null) {
		mediaPlayer.reset();
	}		
	if (adder != null) {
		adder.setSaving(true);
	}
	dos.writeBoolean(flight != null);
	dos.writeBoolean(hyperspace != null);
	if (flight != null) {
		flight.saveScreenState(dos);
	}
	if (hyperspace != null) {
		hyperspace.saveScreenState(dos);
	}
	dos.writeInt(currentLineIndex); // 1 is subtracted in the read object code, because it has to be passed to the constructor.		
	dos.writeChar(savedGalaxySeed[0]);
	dos.writeChar(savedGalaxySeed[1]);
	dos.writeChar(savedGalaxySeed[2]);
	dos.writeInt(savedPresentSystem == null ? -1 : savedPresentSystem.getIndex());
	dos.writeInt(savedHyperspaceSystem == null ? -1 : savedHyperspaceSystem.getIndex());
	dos.writeInt(savedInstalledEquipment.size());
	for (Equipment e: savedInstalledEquipment) {
		dos.writeByte(EquipmentStore.ordinal(e));
	}
	dos.writeInt(savedFuel);
	for (int i = 0; i < 4; i++) {
		dos.writeInt(savedLasers[i] == null ? -1 : EquipmentStore.ordinal(savedLasers[i]));
	}
	for (int i = 0; i < Settings.buttonPosition.length; i++) {
		dos.writeInt(savedButtonConfiguration[i]);
	}	
	dos.writeBoolean(savedDisableTraders);
	dos.writeBoolean(savedDisableAttackers);
	dos.writeInt(savedMissiles);
	dos.writeLong(savedCredits);
	dos.writeInt(savedScore);
	dos.writeInt(savedLegalStatus.ordinal());
	dos.writeInt(savedLegalValue);
	dos.writeInt(savedInventory.length);
	for (InventoryItem w: savedInventory) {
		dos.writeLong(w.getWeight().getWeightInGrams());
		dos.writeLong(w.getPrice());
		dos.writeLong(w.getUnpunished().getWeightInGrams());
	}
	dos.writeLong(time);
	dos.writeInt(savedMarketFluct);
}
 
Example 18
Source File: ControlOptionsScreen.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void saveScreenState(DataOutputStream dos) throws IOException {
	dos.writeBoolean(forwardToIntroduction);
}
 
Example 19
Source File: BytesReadTrackerTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testBytesRead() throws Exception
{
    byte[] testData;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    try
    {
        // boolean
        out.writeBoolean(true);
        // byte
        out.writeByte(0x1);
        // char
        out.writeChar('a');
        // short
        out.writeShort(1);
        // int
        out.writeInt(1);
        // long
        out.writeLong(1L);
        // float
        out.writeFloat(1.0f);
        // double
        out.writeDouble(1.0d);

        // String
        out.writeUTF("abc");
        testData = baos.toByteArray();
    }
    finally
    {
        out.close();
    }

    DataInputStream in = new DataInputStream(new ByteArrayInputStream(testData));
    BytesReadTracker tracker = new BytesReadTracker(in);

    try
    {
        // boolean = 1byte
        boolean bool = tracker.readBoolean();
        assertTrue(bool);
        assertEquals(1, tracker.getBytesRead());
        // byte = 1byte
        byte b = tracker.readByte();
        assertEquals(b, 0x1);
        assertEquals(2, tracker.getBytesRead());
        // char = 2byte
        char c = tracker.readChar();
        assertEquals('a', c);
        assertEquals(4, tracker.getBytesRead());
        // short = 2bytes
        short s = tracker.readShort();
        assertEquals(1, s);
        assertEquals((short) 6, tracker.getBytesRead());
        // int = 4bytes
        int i = tracker.readInt();
        assertEquals(1, i);
        assertEquals(10, tracker.getBytesRead());
        // long = 8bytes
        long l = tracker.readLong();
        assertEquals(1L, l);
        assertEquals(18, tracker.getBytesRead());
        // float = 4bytes
        float f = tracker.readFloat();
        assertEquals(1.0f, f, 0);
        assertEquals(22, tracker.getBytesRead());
        // double = 8bytes
        double d = tracker.readDouble();
        assertEquals(1.0d, d, 0);
        assertEquals(30, tracker.getBytesRead());
        // String("abc") = 2(string size) + 3 = 5 bytes
        String str = tracker.readUTF();
        assertEquals("abc", str);
        assertEquals(35, tracker.getBytesRead());

        assertEquals(testData.length, tracker.getBytesRead());
    }
    finally
    {
        in.close();
    }

    tracker.reset(0);
    assertEquals(0, tracker.getBytesRead());
}
 
Example 20
Source File: PassBooleanByValueBinary.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.writeBoolean(value);
   }