public PacketSelectionUpdate(PlayerInfo info) {
    packet = new Packet250CustomPayload();

    ByteArrayOutputStream streambyte = new ByteArrayOutputStream();
    DataOutputStream stream = new DataOutputStream(streambyte);

    try {
      stream.write(packetID);

      if (info != null && info.getPoint1() != null) {
        Point p1 = info.getPoint1();
        stream.writeBoolean(true);
        stream.writeInt(p1.x);
        stream.writeInt(p1.y);
        stream.writeInt(p1.z);
      } else stream.writeBoolean(false);

      if (info != null && info.getPoint2() != null) {
        Point p2 = info.getPoint2();
        stream.writeBoolean(true);
        stream.writeInt(p2.x);
        stream.writeInt(p2.y);
        stream.writeInt(p2.z);
      } else stream.writeBoolean(false);

      stream.close();
      streambyte.close();

      packet.channel = FECHANNEL;
      packet.data = streambyte.toByteArray();
      packet.length = packet.data.length;
    } catch (Exception e) {
      OutputHandler.SOP("Error creating packet >> " + this.getClass());
    }
  }
 /** Sends out an array containing information about all the connected to the ccserver */
 private void sendConnectedList() {
   // Setup some stuff
   ArrayList<ConnectionThread> currentConnections = parent.getConnectionThread();
   ConnectionThread tempConnection;
   int size = currentConnections.size();
   System.out.println("    Number of users: " + size);
   try {
     // Send packageID
     dos.writeByte(4);
     // Start sending to master how many entry's we will send
     dos.writeInt(size);
     for (int i = 0; i < size; i++) {
       tempConnection = currentConnections.get(i);
       // Send id
       dos.writeInt(tempConnection.getccserverId());
       // Send name
       writeString(tempConnection.getComputerName());
       // Send if in used
       dos.writeBoolean(tempConnection.isInUse());
       // Send if thread is a master
       dos.writeBoolean(tempConnection.isMaster());
     }
   } catch (IOException e) {
     parent.log.printlnErr("IO exception from thread #" + ccserverId + "@sendConnectionList");
     e.printStackTrace();
   }
 }
示例#3
0
  /**
   * Setup response for the IPC Call.
   *
   * @param response buffer to serialize the response into
   * @param call {@link Call} to which we are setting up the response
   * @param status {@link Status} of the IPC call
   * @param rv return value for the IPC Call, if the call was successful
   * @param errorClass error class, if the the call failed
   * @param error error message, if the call failed
   * @throws IOException
   */
  private void setupResponse(
      ByteArrayOutputStream response,
      Call call,
      Status status,
      IOReadableWritable rv,
      String errorClass,
      String error)
      throws IOException {
    response.reset();
    DataOutputStream out = new DataOutputStream(response);
    out.writeInt(call.id); // write call id
    out.writeInt(status.state); // write status

    if (status == Status.SUCCESS) {
      if (rv == null) {
        out.writeBoolean(false);
      } else {
        out.writeBoolean(true);
        StringRecord.writeString(out, rv.getClass().getName());
        rv.write(out);
      }

    } else {
      StringRecord.writeString(out, errorClass);
      StringRecord.writeString(out, error);
    }
    call.setResponse(ByteBuffer.wrap(response.toByteArray()));
  }
示例#4
0
 public static void writeMaybeString(DataOutputStream out, String s) throws IOException {
   if (s != null) {
     out.writeBoolean(true);
     out.writeUTF(s);
   } else {
     out.writeBoolean(false);
   }
 }
 public void writeNullableString(@Nullable CharSequence value) throws IOException {
   if (value == null) {
     outputStream.writeBoolean(false);
   } else {
     outputStream.writeBoolean(true);
     outputStream.writeUTF(value.toString());
   }
 }
 /**
  * Schreiben eines Datensatzes in den übergegebenen DataOutputStream
  *
  * @param out DataOutputStream
  * @throws IOException, wenn ein Fehler beim Schreiben in den Ausgabestream auftritt.
  */
 public final void write(DataOutputStream out) throws IOException {
   _baseSubscriptionInfo.write(out);
   out.writeBoolean(_receiveOptions.withDelayed());
   out.writeBoolean(_receiveOptions.withDelta());
   out.writeBoolean(_receiverRole.isDrain());
   // Ein Byte Länge des nicht mehr benötigten Indikatorbitfelds
   out.writeByte(0);
 }
示例#7
0
 private <T> void encodeOptional(DataOutputStream os, Optional<T> ot, Codec<T> codec)
     throws IOException {
   if (ot.isPresent()) {
     os.writeBoolean(true);
     codec.encode(os, ot.get());
   } else {
     os.writeBoolean(false);
   }
 }
示例#8
0
 public void saveInstance(DataOutputStream stream) throws IOException {
   stream.writeBoolean(this.powered);
   if (this.delay > 0) {
     stream.writeInt(this.setdelay);
     if (this.setdelay > 0) {
       stream.writeBoolean(this.setpowered);
     }
   }
 }
示例#9
0
 public static void writeMaybeInt(DataOutputStream out, boolean exists, int value)
     throws IOException {
   if (exists) {
     out.writeBoolean(true);
     out.writeInt(value);
   } else {
     out.writeBoolean(false);
   }
 }
示例#10
0
  public void Serialize(DataOutputStream stream) throws IOException {
    stream.writeInt(TCDefaultValues.ProtocolVersion.intValue());

    WriteStringToStream(stream, this.WorldName);

    stream.writeInt(this.GenerationDepth);
    stream.writeInt(this.BiomeRarityScale);
    stream.writeInt(this.LandRarity);
    stream.writeInt(this.LandSize);
    stream.writeInt(this.LandFuzzy);
    stream.writeInt(this.IceRarity);
    stream.writeInt(this.IceSize);
    stream.writeBoolean(this.FrozenOcean);
    stream.writeBoolean(this.FrozenRivers);
    stream.writeInt(this.RiverRarity);
    stream.writeInt(this.RiverSize);
    stream.writeBoolean(this.RiversEnabled);

    stream.writeDouble(this.oldBiomeSize);

    stream.writeFloat(this.minTemperature);
    stream.writeFloat(this.maxTemperature);
    stream.writeFloat(this.minMoisture);
    stream.writeFloat(this.maxMoisture);

    stream.writeInt(this.WorldFog);
    stream.writeInt(this.WorldNightFog);

    stream.writeInt(this.CustomBiomes.size());
    for (String name : this.CustomBiomes) {
      WriteStringToStream(stream, name);
      stream.writeInt(this.CustomBiomeIds.get(name));
    }

    stream.writeInt(this.biomes.size());
    for (BiomeConfig config : this.biomes) {
      stream.writeInt(config.Biome.getId());
      config.Serialize(stream);
    }

    stream.writeInt(this.NormalBiomes.size());
    for (String biome : this.NormalBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.IceBiomes.size());
    for (String biome : this.IceBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.IsleBiomes.size());
    for (String biome : this.IsleBiomes) WriteStringToStream(stream, biome);

    stream.writeInt(this.BorderBiomes.size());
    for (String biome : this.BorderBiomes) WriteStringToStream(stream, biome);
  }
示例#11
0
文件: Task.java 项目: devratans/dhis2
 @Override
 public void serializeVerssion2_8(DataOutputStream dout) throws IOException {
   dout.writeInt(this.getId());
   dout.writeInt(this.getProgramStageId());
   dout.writeInt(this.getProgramId());
   dout.writeBoolean(this.isCompleted());
 }
示例#12
0
  public void writeBinaryStream(String bytes) {
    try {
      if (dos != null) {
        for (int i = 0; i < 1; i++) {
          // write boolean value.
          dos.writeBoolean(true);

          // "C1 01 00 00 14 00 00 0D 00 00 FF 05
          // 00010102021101010102030904020A0000090600000A0064FF120001"
          // dos.write(b);
          // dos.writeChars("\n");
          //
          //	dos.writeChars("C10100001400000D0000FF0500010102021101010102030904020A0000090600000A0064FF120001");
          //					dos.writeChars("\n");
          //
          //	dos.writeChars("C10100001400000D0000FF08000101020809067765656B30301104110511021101110211041101");
          //					dos.writeChars("\n");
          //
          //	dos.writeChars("C10100001400000D0000FF070001010203090673656173306E090C07DC0B0001FFFFFF0080000009077765656B303020");
          //					dos.writeChars("\n");
          //					dos.writeChars("C10100000B00000B0000FF0200010102031200010905056F0615031101");

          dos.writeChars(bytes);
        }
        dos.flush();
        dos.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#13
0
  public static void main(String args[]) {
    OutputStream f = null;
    try {
      f = new FileOutputStream(args[0]);
    } catch (IOException e) {
      System.out.println("Apertura fallita");
      e.printStackTrace();
      // System.exit(1);
    }

    String a = "grgregre";

    DataOutputStream df = new DataOutputStream(f);

    float f1 = 5.1415F;
    char c1 = 'X';
    boolean b1 = true;
    double d1 = 1.4141;
    try {

      df.writeFloat(f1);
      df.writeBoolean(b1);
      df.writeDouble(d1);
      df.writeChar(c1);
      df.writeInt(11);
      df.close();
    } catch (IOException e) {
      e.printStackTrace();
      System.out.println("Scrittura fallita");

      // System.exit(1);
    }
  }
 @Override
 public void writeData(DataOutputStream output) throws IOException {
   super.writeData(output);
   PacketUtil.writeString(output, getText());
   output.writeBoolean(isCentered());
   output.writeInt(getHexColor());
 }
示例#15
0
文件: Main.java 项目: babymills/nhnh
  public static void main(String[] args) throws IOException {
    try (DataOutputStream dout = new DataOutputStream(new FileOutputStream("Test.dat"))) {
      dout.writeDouble(98.6);
      dout.writeInt(123);
      dout.writeBoolean(true);
    } catch (FileNotFoundException e) {
      System.out.println("Cannot Open Output");
      return;
    } catch (IOException e) {
      System.out.println("I/O Ero " + e);
    }

    try (DataInputStream din = new DataInputStream(new FileInputStream("Test.dat"))) {
      double d = din.readDouble();

      int i = din.readInt();
      boolean b = din.readBoolean();
      System.out.println("Gere are the values " + b + " " + i + " " + d);
    } catch (FileNotFoundException e) {
      System.out.println("Cannot Open Output");
      return;
    } catch (IOException e) {
      System.out.println("I/O Ero " + e);
    }
  }
示例#16
0
 @Override
 public void createInitPacket(DataOutputStream outStream) throws IOException {
   if (inventory[0] != null) {
     outStream.writeInt(inventory[0].itemID);
     outStream.writeInt(inventory[0].getItemDamage());
   } else {
     outStream.writeInt(0);
     outStream.writeInt(0);
   }
   if (inventory[1] != null) {
     outStream.writeInt(inventory[1].itemID);
     outStream.writeInt(inventory[1].getItemDamage());
   } else {
     outStream.writeInt(0);
     outStream.writeInt(0);
   }
   if (inventory[2] != null) {
     outStream.writeInt(inventory[2].itemID);
     outStream.writeInt(inventory[2].getItemDamage());
   } else {
     outStream.writeInt(0);
     outStream.writeInt(0);
   }
   if (inventory[3] != null) {
     outStream.writeInt(inventory[3].itemID);
     outStream.writeInt(inventory[3].getItemDamage());
   } else {
     outStream.writeInt(0);
     outStream.writeInt(0);
   }
   outStream.writeBoolean(hasRack);
 }
示例#17
0
  public static Packet buildSoundPacket(double x, double y, double z, String s, boolean distort) {
    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = channelFlan;

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    try {
      data.write(packetID); // this is the packet ID. identifies it as a BreakSoundPacket
      data.writeFloat((float) x);
      data.writeFloat((float) y);
      data.writeFloat((float) z);
      data.writeUTF(s);
      data.writeBoolean(distort);

      packet.data = bytes.toByteArray();
      packet.length = packet.data.length;

      data.close();
      bytes.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return packet;
  }
示例#18
0
  public static void main(String[] args) throws IOException {
    // open file output stream
    File outFile = new File("data");
    FileOutputStream outStream = new FileOutputStream(outFile);
    DataOutputStream outDataStream = new DataOutputStream(outStream);

    // write an int, boolean, double
    outDataStream.writeInt(44);
    outDataStream.writeBoolean(true);
    outDataStream.writeDouble(7.2);

    outDataStream.close();

    // open file input stream
    File inFile = new File("data");
    FileInputStream inStream = new FileInputStream(inFile);
    DataInputStream inDataStream = new DataInputStream(inStream);

    // read an int, boolean, double
    int n = inDataStream.readInt();
    boolean b = inDataStream.readBoolean();
    double d = inDataStream.readDouble();

    inDataStream.close();

    // what did we get?
    System.out.println("n = " + n);
    System.out.println("b = " + b);
    System.out.println("d = " + d);

    // can we add n to d?
    System.out.println("n + d = " + (n + d));
  }
示例#19
0
  public static void main(String[] args) throws IOException {
    // Create a FileOutputStream.
    FileOutputStream outputFile = new FileOutputStream("primitives.data");

    // Create a DataOutputStream which is chained to the FileOutputStream.
    DataOutputStream outputStream = new DataOutputStream(outputFile);

    // Write Java primitive values in binary representation:
    outputStream.writeBoolean(true);
    outputStream.writeChar('A'); // int written as Unicode char
    outputStream.writeByte(Byte.MAX_VALUE); // int written as 8-bits byte
    outputStream.writeShort(Short.MIN_VALUE); // int written as 16-bits short
    outputStream.writeInt(Integer.MAX_VALUE);
    outputStream.writeLong(Long.MIN_VALUE);
    outputStream.writeFloat(Float.MAX_VALUE);
    outputStream.writeDouble(Math.PI);

    // Close the output stream, which also closes the underlying stream.
    outputStream.flush();
    outputStream.close();

    // Create a FileInputStream.
    FileInputStream inputFile = new FileInputStream("primitives.data");

    // Create a DataInputStream which is chained to the FileInputStream.
    DataInputStream inputStream = new DataInputStream(inputFile);

    // Read the binary representation of Java primitive values
    // in the same order they were written out:
    boolean v = inputStream.readBoolean();
    char c = inputStream.readChar();
    byte b = inputStream.readByte();
    short s = inputStream.readShort();
    int i = inputStream.readInt();
    long l = inputStream.readLong();
    float f = inputStream.readFloat();
    double d = inputStream.readDouble();

    // Check for end of stream:
    try {
      int value = inputStream.readByte();
      System.out.println("More input: " + value);
    } catch (EOFException eofe) {
      System.out.println("End of stream");
    } finally {
      // Close the input stream, which also closes the underlying stream.
      inputStream.close();
    }

    // Write the values read to the standard input stream:
    System.out.println("Values read:");
    System.out.println(v);
    System.out.println(c);
    System.out.println(b);
    System.out.println(s);
    System.out.println(i);
    System.out.println(l);
    System.out.println(f);
    System.out.println(d);
  }
 private void writeBool(boolean v) {
   try {
     outStream.writeBoolean(v);
   } catch (IOException e) {
     IOError();
   }
 }
示例#21
0
 /**
  * Helper method to write nullable text
  *
  * @param text the text that could be null
  * @param out the output stream
  * @throws IOException when writing fails
  * @see #readUtfNullable(String, DataInputStream)
  */
 public static void writeUtfNullable(String text, DataOutputStream out) throws IOException {
   boolean isNull = (text == null);
   out.writeBoolean(isNull);
   if (!isNull) {
     out.writeUTF(text);
   }
 }
示例#22
0
 public void func_73273_a(DataOutputStream p_73273_1_) throws IOException {
   func_73271_a(this.field_73468_a, p_73273_1_);
   p_73273_1_.writeByte(this.field_73466_b);
   p_73273_1_.writeByte(this.field_73467_c | (this.field_73464_d ? 1 : 0) << 3);
   p_73273_1_.writeByte(this.field_73465_e);
   p_73273_1_.writeBoolean(this.field_82564_f);
 }
示例#23
0
 private void sendResponse(long requestId, Object value, Class<?> declaredType)
     throws IOException {
   DataOutputStream out = newFlusher();
   out.writeByte(RESPONSE);
   out.writeLong(requestId);
   if (value == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     Class<?> clazz = value.getClass();
     out.writeUTF(clazz.getName());
     Serializer<Object> s = serializerFor(clazz, declaredType);
     s.serialize(out, value);
   }
   out.writeBoolean(false);
   out.flush();
 }
示例#24
0
  public void writeData(DataOutputStream data) throws IOException {

    for (int i = 0; i < IPipe.WireColor.values().length; i++) {
      data.writeBoolean(_hasWire[i]);
      _wires[i].writeData(data);
      data.writeInt(_wireIconIndex[i]);
    }
  }
示例#25
0
 @Override
 public void send(DataOutputStream s) throws IOException {
   super.send(s);
   s.writeInt(id);
   s.writeBoolean(this.isError);
   s.writeUTF(this.message);
   s.flush();
 }
示例#26
0
 public void func_73273_a(DataOutputStream p_73273_1_) throws IOException {
   p_73273_1_.writeInt(this.field_73567_a);
   p_73273_1_.writeInt(this.field_73566_c);
   p_73273_1_.writeByte(this.field_73563_d & 255);
   p_73273_1_.writeInt(this.field_73564_e);
   p_73273_1_.writeInt(this.field_73565_b);
   p_73273_1_.writeBoolean(this.field_82561_f);
 }
示例#27
0
 public void serialize(DataOutputStream dos) throws IOException {
   dos.writeInt(this.getId());
   dos.writeUTF(this.getName());
   dos.writeUTF(this.getType());
   dos.writeBoolean(this.isCompulsory());
   this.categoryOptionCombos.serialize(dos);
   this.optionSet.serialize(dos);
 }
示例#28
0
 @Override
 public void writeData(DataOutputStream output) throws IOException {
   PacketUtil.writeString(output, fileName);
   PacketUtil.writeString(output, plugin);
   output.writeBoolean(compressed);
   output.writeInt(fileData.length);
   output.write(fileData);
 }
示例#29
0
 private void writePrefs() {
   try {
     DataOutputStream prefs = new DataOutputStream(new FileOutputStream(m_PrefsFileName));
     prefs.writeInt(m_PortIndex);
     prefs.writeBoolean(m_IsNative);
   } catch (IOException ee) {
   }
 }
 @Override
 public void write(DataOutputStream out) throws IOException {
   out.writeByte(this.id);
   out.writeByte(this.type);
   IOUtils.writeString(out, this.name);
   out.writeByte(this.slots);
   out.writeBoolean(this.useTitle);
 }