Example #1
0
 /**
  * Writes a primitive value to this stream preceeded by a tag describing the type and data size
  * (in bytes) of the value.
  *
  * @param tag a <code>JDWP.Tag_...</code> value
  * @param value the value to write
  * @throws IOException if there was an IO error while writing
  */
 public void writePrimitive(byte tag, long value, String s) throws IOException {
   if (ENABLE_VERBOSE && s != null && Log.verbose()) Log.log("out[t-prim]:  " + s + "=" + value);
   dos.writeByte(tag);
   switch (tag) {
     case JDWP.Tag_VOID:
       break;
     case JDWP.Tag_BYTE:
     case JDWP.Tag_BOOLEAN:
       dos.writeByte((byte) value);
       break;
     case JDWP.Tag_CHAR:
     case JDWP.Tag_SHORT:
       dos.writeShort((short) value);
       break;
     case JDWP.Tag_INT:
     case JDWP.Tag_FLOAT:
       dos.writeInt((int) value);
       break;
     case JDWP.Tag_LONG:
     case JDWP.Tag_DOUBLE:
       dos.writeLong(value);
       break;
     default:
       Assert.shouldNotReachHere();
   }
 }
Example #2
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    DataInputStream input = new DataInputStream(request.getInputStream());

    byte buff[];
    int leido = input.readByte();
    int tamano = leido;
    buff = new byte[tamano];
    leido = input.read(buff, 0, tamano);
    if (leido < tamano) {
      log.error("final inesperado");
      throw new IOException("Se leyo menos de los esperado");
    }
    input.close();
    String login = new String(buff);
    UsuarioDao dao = new UsuarioDao();
    BeanUsuario usuario = dao.getUsuarioByLogin(login);
    DataOutputStream output = new DataOutputStream(response.getOutputStream());
    if (usuario != null) {
      output.writeByte(1);
      usuario.write(output);
    } else {
      output.writeByte(0);
    }
    output.close();
  }
Example #3
0
 // -----------------------------------------------------------
 // for "SrvRqst"
 // find the matched URLs with (type, scope, predicate, ltag)
 // return: error code (short)
 //         number of matched URLs (short)
 //         URL blocks (decided bt previous #URL)
 // -----------------------------------------------------------
 public synchronized byte[] getMatchedURL(String type, String scope, String pred, String ltag) {
   byte[] buf = null;
   int ecode = Const.OK;
   if (!Util.shareString(daf.getScope(), scope, ",")) {
     ecode = Const.SCOPE_NOT_SUPPORTED;
   }
   b.reset();
   try {
     int count = 0;
     d.writeShort(ecode); // error code
     d.writeShort(count); // URL count, place holder
     if (ecode == Const.OK) { // no error, find matched URLs
       Iterator values = table.values().iterator();
       while (values.hasNext()) {
         Entry e = (Entry) values.next();
         if (e.match(type, scope, pred, ltag)) {
           count++;
           d.writeByte(0);
           d.writeShort(e.getLifetime());
           d.writeShort(e.getURL().length());
           d.writeBytes(e.getURL());
           d.writeByte(0);
         }
       }
     }
     buf = b.toByteArray();
     if (count > 0) Util.writeInt(buf, 2, count, 2); // update count
   } catch (Exception e) {
     if (ServiceLocationManager.displayMSLPTrace) e.printStackTrace();
   }
   return buf;
 }
Example #4
0
 /**
  * Write a binary representation of this URI.
  *
  * @param dos The stream to write to.
  * @throws MalformedURLException If the key could not be written because of inconsistencies or
  *     other problems in the key itself.
  * @throws IOException If an error occurred while writing the key.
  */
 private void writeFullBinaryKey(DataOutputStream dos) throws IOException {
   if (keyType.equals("CHK")) dos.writeByte(CHK);
   else if (keyType.equals("SSK")) dos.writeByte(SSK);
   else if (keyType.equals("KSK")) dos.writeByte(KSK);
   else if (keyType.equals("USK"))
     throw new MalformedURLException("Cannot write USKs as binary keys");
   else
     throw new MalformedURLException("Cannot write key of type " + keyType + " - do not know how");
   if (!keyType.equals("KSK")) {
     if (routingKey.length != 32)
       throw new MalformedURLException("Routing key must be of length 32");
     dos.write(routingKey);
     if (cryptoKey.length != 32)
       throw new MalformedURLException("Crypto key must be of length 32");
     dos.write(cryptoKey);
     if (keyType.equals("CHK") && (extra.length != Constants.CLIENT_CHK_EXTRA_LENGTH))
       throw new MalformedURLException("Wrong number of extra bytes for CHK");
     if (keyType.equals("SSK") && (extra.length != Constants.CLIENT_SSK_EXTRA_LENGTH))
       throw new MalformedURLException("Wrong number of extra bytes for SSK");
     dos.write(extra);
   }
   if (!keyType.equals("CHK")) dos.writeUTF(docName);
   if (metaStr != null) {
     dos.writeInt(metaStr.length);
     for (int i = 0; i < metaStr.length; i++) dos.writeUTF(metaStr[i]);
   } else dos.writeInt(0);
 }
  public int write(DataOutputStream ostream) throws IOException {
    preWrite();
    int retVal = 0;

    {
      /** fix dependent sizes for desc_header * */
    }

    {
      /** fix dependent sizes for service_name * */
    }

    // write desc_header
    if (desc_header != null) retVal += desc_header.write(ostream);
    // write service_id
    {
      ostream.writeByte((service_id & 0x00FF0000) >> 16);
      ostream.writeShort((service_id & 0x0000FFFF));
      retVal += 3;
    }
    // write bf1
    ostream.writeByte(bf1.getValue());
    retVal += 1;
    // write service_name
    {
      retVal += service_name.write(ostream);
    }
    postWrite();
    return retVal;
  }
Example #6
0
 @Override
 public void writeToBinary(OutputStream out) {
   DataOutputStream dos = new DataOutputStream(out);
   try {
     dos.writeByte(getID());
     new DataString(getName()).writeToBinary(out);
     new DataString(getSource()).writeToBinary(out);
     dos.writeShort(getPositionX());
     dos.writeShort(getPositionY());
     dos.writeShort(getSourceX());
     dos.writeShort(getSourceY());
     dos.writeShort(getSourceWidth());
     dos.writeShort(getSourceHeight());
     dos.writeShort(getDestinationWidth());
     dos.writeShort(getDestinationHeight());
     dos.writeShort(getAnchorX());
     dos.writeShort(getAnchorY());
     dos.writeShort(getScaleX());
     dos.writeShort(getScaleY());
     dos.writeInt(getColour());
     dos.writeShort(getOpacity());
     dos.writeByte(getRotation());
     for (Animation animation : animations) {
       animation.writeToBinary(out);
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 private void writeHeader(DataOutputStream stream, int nParents, int nRecords, int nVariables)
     throws IOException {
   stream.writeByte(1); // Version number 1
   stream.writeByte(nParents); // Max number of parents
   stream.writeInt(nRecords); // Number of records
   stream.writeInt(nVariables); // Number of variables
 }
 public void a(DataOutputStream paramDataOutputStream) {
   paramDataOutputStream.writeInt(this.a);
   paramDataOutputStream.writeByte(this.e);
   paramDataOutputStream.writeInt(this.b);
   paramDataOutputStream.writeByte(this.c);
   paramDataOutputStream.writeInt(this.d);
 }
 private void writeBuf() throws IOException {
   if (buf.size() > 0) {
     if (zeroAdditions && (buf.size() >= this.zeroMinBlock) && (winRatio < zeroRatio)) {
       int s = buf.size();
       buf.reset();
       for (int i = 0; i < s; i++) {
         buf.write(0);
       }
     }
     if (buf.size() <= data_max) {
       output.writeByte(buf.size());
       written += buf.size() + 1;
     } else if (buf.size() <= 32767) {
       output.writeByte(DATA_USHORT);
       output.writeShort(buf.size());
       written += buf.size() + 3;
     } else {
       output.writeByte(DATA_INT);
       output.writeInt(buf.size());
       written += buf.size() + 5;
     }
     buf.writeTo(output);
     buf.reset();
   }
 }
Example #10
0
 public static Packet getPacket(TileEntityIronChest tileEntityIronChest) {
   ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
   DataOutputStream dos = new DataOutputStream(bos);
   int x = tileEntityIronChest.xCoord;
   int y = tileEntityIronChest.yCoord;
   int z = tileEntityIronChest.zCoord;
   int typ = tileEntityIronChest.getType().ordinal();
   int[] items = tileEntityIronChest.buildIntDataList();
   boolean hasStacks = (items != null);
   try {
     dos.writeInt(x);
     dos.writeInt(y);
     dos.writeInt(z);
     dos.writeByte(typ);
     dos.writeByte(hasStacks ? 1 : 0);
     if (hasStacks) {
       for (int i = 0; i < 24; i++) {
         dos.writeInt(items[i]);
       }
     }
   } catch (IOException e) {
     // UNPOSSIBLE?
   }
   Packet250CustomPayload pkt = new Packet250CustomPayload();
   pkt.channel = "IronChest";
   pkt.data = bos.toByteArray();
   pkt.length = bos.size();
   pkt.isChunkDataPacket = true;
   return pkt;
 }
Example #11
0
 public void sendMessage(String sendMessage) {
   try {
     out = new DataOutputStream(socket2.getOutputStream());
     if (sendMessage.equals("Windows")) {
       out.writeByte(0x1);
       out.flush();
       return;
     }
     if (sendMessage.equals("Unix")) {
       out.writeByte(0x2);
       out.flush();
       return;
     }
     if (sendMessage.equals("Linux")) {
       out.writeByte(0x3);
       out.flush();
     } else {
       out.writeUTF(sendMessage);
       out.flush();
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     if (out != null) {
       try {
         out.close();
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   }
 }
  public void marshal(DataOutputStream dos) {
    super.marshal(dos);
    try {
      minefieldID.marshal(dos);
      requestingEntityID.marshal(dos);
      dos.writeByte((byte) requestID);
      dos.writeByte((byte) requestedPerimeterPoints.size());
      dos.writeByte((byte) pad2);
      dos.writeByte((byte) sensorTypes.size());
      dos.writeInt((int) dataFilter);
      requestedMineType.marshal(dos);

      for (int idx = 0; idx < requestedPerimeterPoints.size(); idx++) {
        Point aPoint = requestedPerimeterPoints.get(idx);
        aPoint.marshal(dos);
      } // end of list marshalling

      for (int idx = 0; idx < sensorTypes.size(); idx++) {
        TwoByteChunk aTwoByteChunk = sensorTypes.get(idx);
        aTwoByteChunk.marshal(dos);
      } // end of list marshalling

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of marshal method
  /**
   * protocol methods *
   *
   * @param toBeSent
   * @exception IOException Description of Exception
   */
  private void frameSend(String toBeSent) throws IOException {
    if (sendLimit < MAX_POINTS) {
      sendLimit += ((System.currentTimeMillis() - lastFrameSendTime) / RECOVER_RATE);
      // never let the limit exceed the max, else this code won't work
      // right
      sendLimit = Math.min(MAX_POINTS, sendLimit);
      if (sendLimit < MAX_POINTS) {
        // sendLimit could be less than 0, this still works properly
        logger.info("Current send limit=" + sendLimit + " out of " + MAX_POINTS);
        /* try {
            // this will wait for every point below the max
            int waitAmount = MAX_POINTS - sendLimit;
            logger.info("Delaying send " + waitAmount + " units");
            //Thread.sleep(RECOVER_RATE * waitAmount);
            sendLimit += waitAmount;
        } catch (InterruptedException ie) {
        }*/
      }
    }
    out.writeByte(42); // *
    out.writeByte(2); // DATA
    out.writeShort(seqNo); // SEQ NO
    seqNo = (seqNo + 1) & 65535;
    out.writeShort(toBeSent.length()); // DATA SIZE
    out.writeBytes(toBeSent); // DATA
    out.flush();

    // sending is more expensive the higher our warning level
    // this should decrement between 1 and 10 points (exponentially)
    int warnAmount = getBuddy(this.name).getWarningAmount();
    sendLimit -= (1 + Math.pow((3 * warnAmount) / 100, 2));
    lastFrameSendTime = System.currentTimeMillis();
  }
 public GDiffWriter(
     DataOutputStream os,
     int skipHeaders,
     boolean differential,
     boolean zeroAdditions,
     int zeroMinBlock,
     double zeroRatio)
     throws IOException {
   this.differential = differential;
   this.output = os;
   this.skipHeaders = skipHeaders;
   this.zeroAdditions = zeroAdditions;
   this.zeroRatio = zeroRatio;
   if (zeroMinBlock > 0) { // otherwise use default
     this.zeroMinBlock = zeroMinBlock;
   }
   // write magic string "d1 ff d1 ff 04"
   if ((skipHeaders & SKIP_HEADER) == 0) {
     output.writeByte(0xd1);
     output.writeByte(0xff);
     output.writeByte(0xd1);
     output.writeByte(0xff);
     if (differential) {
       output.writeByte(0x05); // magic string extension
       data_max = 243;
     } else {
       output.writeByte(0x04);
     }
     written = 5;
   }
 }
Example #15
0
 public void endOfData() throws IOException {
   byte desc;
   // the first data channel to quit
   // will send EOF. There musn't be more than
   // 1 EOF per stripe.
   synchronized (context) {
     if (context.eodsTransferred == 0) {
       desc = EOF | EOD;
       output.writeByte(desc);
       output.writeLong(0);
       output.writeLong(context.eodsTotal);
       logger.debug("wrote EOF (expected EODS: " + context.eodsTotal + ") and EOD");
     } else {
       desc = EOD;
       output.writeByte(desc);
       output.writeLong(0);
       output.writeLong(0);
       logger.debug("wrote EOD");
     }
     context.eodTransferred();
   }
   // important to flush, otherwise transfer will hang
   // with data and EOD remaining in the output buffer
   output.flush();
 }
Example #16
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);
 }
 @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);
 }
 @Override
 public void encode(DataOutputStream out) throws IOException {
   out.writeInt(x);
   out.writeShort(y);
   out.writeInt(z);
   out.writeByte(instrumentType);
   out.writeByte(pitch);
 }
 public void writePacketData(DataOutputStream dos) {
   try {
     dos.writeByte(this.buttonId);
     dos.writeByte((byte) this.probability);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #20
0
 public void iload(int i) throws IOException {
   if (i >= 0 && i < 4) {
     code.writeByte(26 + i);
   } else {
     code.writeByte(21);
     code.writeByte(i);
   }
   push(1);
 }
Example #21
0
 private void writeMessage(int type, int message) {
   try {
     out.writeByte((int) '!');
     out.writeByte(type);
     out.writeByte(message);
   } catch (IOException e) {
     removePlayer();
   }
 }
Example #22
0
 public void lload(int i) throws IOException {
   if (i >= 0 && i < 4) {
     code.writeByte(30 + i);
   } else {
     code.writeByte(22);
     code.writeByte(i);
   }
   push(2);
 }
Example #23
0
 public void istore(int i) throws IOException {
   if (i >= 0 && i < 4) {
     code.writeByte(59 + i);
   } else {
     code.writeByte(54);
     code.writeByte(i);
   }
   push(-1);
 }
 public void writeExternal(DataOutputStream out) throws IOException {
   if (d == (int) d) {
     out.writeByte(0x00);
     ExtUtil.writeNumeric(out, (int) d);
   } else {
     out.writeByte(0x01);
     ExtUtil.writeDecimal(out, d);
   }
 }
Example #25
0
 public void save(
     File file, byte[] program, final int programOffset, final int c64dataLen, final int loadAddr)
     throws IOException {
   try (DataOutputStream dout = new DataOutputStream(new FileOutputStream(file))) {
     dout.writeByte(loadAddr & 0xff);
     dout.writeByte((loadAddr >> 8) & 0xff);
     dout.write(program, programOffset, c64dataLen);
   }
 }
Example #26
0
 @Override
 public void write(DataOutputStream out) throws IOException {
   out.writeInt(this.entityId);
   IOUtils.writeString(out, this.levelType);
   out.writeByte(this.gameMode);
   out.writeByte(this.dimension);
   out.writeByte(this.difficulty);
   out.writeByte(this.unused);
   out.writeByte(this.maxPlayers);
 }
Example #27
0
 static byte[] Cmd_Finish() throws Exception {
   ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
   DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
   writeInt(-1, dataoutputstream);
   dataoutputstream.writeByte(75);
   dataoutputstream.writeByte(0);
   dataoutputstream.writeBytes("FINISH");
   dataoutputstream.writeByte(0);
   return bytearrayoutputstream.toByteArray();
 }
Example #28
0
 public void writePacketData(DataOutputStream dataoutputstream) throws IOException {
   dataoutputstream.writeInt(entityId);
   dataoutputstream.writeByte(type);
   dataoutputstream.writeInt(xPosition);
   dataoutputstream.writeInt(yPosition);
   dataoutputstream.writeInt(zPosition);
   dataoutputstream.writeByte(yaw);
   dataoutputstream.writeByte(pitch);
   metaData.writeWatchableObjects(dataoutputstream);
 }
Example #29
0
 static byte[] Cmd_Challenge() throws Exception {
   ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
   DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
   writeInt(-1, dataoutputstream);
   dataoutputstream.writeByte(74);
   dataoutputstream.writeByte(0);
   dataoutputstream.writeBytes("CHALLENGE");
   dataoutputstream.writeByte(0);
   return bytearrayoutputstream.toByteArray();
 }
  public void sendPacket(
      double posX, double posY, double posZ, float strength, List list, Vec3 vec3) {
    if (worldObj.isRemote) {
      return;
    }

    final ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
    final DataOutputStream dos = new DataOutputStream(bos);
    try {
      dos.writeInt(1);
      dos.writeDouble(posX);
      dos.writeDouble(posY);
      dos.writeDouble(posZ);
      dos.writeFloat(strength);
      dos.write(list.size());

      final int var2 = (int) posX;
      final int var3 = (int) posY;
      final int var4 = (int) posZ;
      final Iterator var5 = list.iterator();

      while (var5.hasNext()) {
        final ChunkPosition var6 = (ChunkPosition) var5.next();
        final int var7 = var6.x - var2;
        final int var8 = var6.y - var3;
        final int var9 = var6.z - var4;
        dos.writeByte(var7);
        dos.writeByte(var8);
        dos.writeByte(var9);
      }

      if (vec3 != null) {
        dos.writeFloat((float) vec3.xCoord);
        dos.writeFloat((float) vec3.yCoord);
        dos.writeFloat((float) vec3.xCoord);
      } else {

        dos.writeFloat(0.0F);
        dos.writeFloat(0.0F);
        dos.writeFloat(0.0F);
      }
    } catch (final IOException e) {
      // UNPOSSIBLE?
    }
    final Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "MetallurgyBase";
    packet.data = bos.toByteArray();
    packet.length = bos.size();
    packet.isChunkDataPacket = true;

    if (packet != null) {
      PacketDispatcher.sendPacketToAllAround(
          posX, posY, posZ, 16, worldObj.provider.dimensionId, packet);
    }
  }