protected String[] readNextPair(DataInputStream inputStream) throws IOException {
   if (inputStream.available() == 0) {
     return null;
   }
   int keySize;
   int valueSize;
   try {
     keySize = inputStream.readInt();
     valueSize = inputStream.readInt();
   } catch (IOException e) {
     throw new EOFException("the file is corrupt or has an incorrect format");
   }
   if (keySize < 1
       || valueSize < 1
       || inputStream.available() < keySize
       || inputStream.available() < valueSize
       || inputStream.available() < keySize + valueSize) {
     throw new EOFException("the file is corrupt or has an incorrect format");
   }
   byte[] keyBytes = new byte[keySize];
   byte[] valueBytes = new byte[valueSize];
   if (inputStream.read(keyBytes) != keySize || inputStream.read(valueBytes) != valueSize) {
     throw new EOFException("the file is corrupt or has an incorrect format");
   }
   String[] pair = new String[2];
   pair[0] = new String(keyBytes, StandardCharsets.UTF_8);
   pair[1] = new String(valueBytes, StandardCharsets.UTF_8);
   return pair;
 }
  private void receiveMessages() throws IOException {
    // handshake (true) endpoint versions
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    // if this version is < the MS version the other node is trying
    // to connect with, the other node will disconnect
    out.writeInt(MessagingService.current_version);
    out.flush();
    DataInputStream in = new DataInputStream(socket.getInputStream());
    int maxVersion = in.readInt();
    // outbound side will reconnect if necessary to upgrade version
    assert version <= MessagingService.current_version;
    from = CompactEndpointSerializationHelper.deserialize(in);
    // record the (true) version of the endpoint
    MessagingService.instance().setVersion(from, maxVersion);
    logger.debug(
        "Set version for {} to {} (will use {})",
        from,
        maxVersion,
        MessagingService.instance().getVersion(from));

    if (compressed) {
      logger.debug("Upgrading incoming connection to be compressed");
      in = new DataInputStream(new SnappyInputStream(socket.getInputStream()));
    } else {
      in = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 4096));
    }

    while (true) {
      MessagingService.validateMagic(in.readInt());
      receiveMessage(in, version);
    }
  }
Exemplo n.º 3
1
  public static MyProtocol read(InputStream in, boolean closeIO) throws IOException {
    if (in != null) {
      MyProtocol protocol = new MyProtocol();
      DataInputStream din = new DataInputStream(in);

      int version = din.readInt();
      protocol.setVersion(version);
      System.out.println(version);

      long code = din.readLong();
      protocol.setCode(code);
      System.out.println(code);

      long fUserId = din.readLong();
      protocol.setfUserId(fUserId);
      System.out.println(fUserId);

      long tUserId = din.readLong();
      protocol.settUserId(tUserId);
      System.out.println(tUserId);

      int length = din.readInt();
      protocol.setLength(length);
      System.out.println(length);

      String content = din.readUTF();
      protocol.setContent(content);
      System.out.println(content);

      if (closeIO) din.close();
      return protocol;
    }
    return null;
  }
Exemplo n.º 4
1
  public String readString() throws IOException {
    if (debug) {
      OLogManager.instance()
          .info(this, "%s - Reading string (4+N bytes)...", socket.getRemoteSocketAddress());
      final int len = in.readInt();
      if (len < 0) return null;

      // REUSE STATIC BUFFER?
      final byte[] tmp = new byte[len];
      in.readFully(tmp);

      updateMetricReceivedBytes(OBinaryProtocol.SIZE_INT + len);

      final String value = new String(tmp);
      OLogManager.instance()
          .info(this, "%s - Read string: %s", socket.getRemoteSocketAddress(), value);
      return value;
    }

    final int len = in.readInt();
    if (len < 0) return null;

    final byte[] tmp = new byte[len];
    in.readFully(tmp);

    updateMetricReceivedBytes(OBinaryProtocol.SIZE_INT + len);

    return new String(tmp);
  }
Exemplo n.º 5
1
  // Loads traffic from file
  public final void load() {
    sessionInTraffic = 0;
    sessionOutTraffic = 0;
    savedCost = 0;
    lastTimeUsed = new Date(1);
    costPerDaySum = 0;
    savedSince = new Date();
    Storage traffic = new Storage("traffic");
    try {
      traffic.open(false);

      byte[] buf = traffic.getRecord(2);
      ByteArrayInputStream bais = new ByteArrayInputStream(buf);
      DataInputStream dis = new DataInputStream(bais);

      allInTraffic = dis.readInt();
      allOutTraffic = dis.readInt();
      savedSince.setTime(dis.readLong());
      lastTimeUsed.setTime(dis.readLong());
      savedCost = dis.readInt();
    } catch (Exception e) {
      savedSince.setTime(new Date().getTime());
      allInTraffic = 0;
      sessionOutTraffic = 0;
      savedCost = 0;
    }
    traffic.close();
  }
Exemplo n.º 6
1
Arquivo: bp.java Projeto: ZoneMo/test
 private static long[] Fm() {
   long[] arrayOfLong = {0L, 0L};
   File localFile = new File(cFH);
   if (!localFile.exists()) return arrayOfLong;
   DataInputStream localDataInputStream;
   int i;
   try {
     localDataInputStream = new DataInputStream(new FileInputStream(localFile));
     i = localDataInputStream.readInt();
     if ((i < 180L) || (i > 3600L)) {
       localDataInputStream.close();
       return arrayOfLong;
     }
   } catch (Exception localException) {
     new StringBuilder("getFromFile Exception:").append(localException.getStackTrace()).toString();
     return arrayOfLong;
   }
   long l = i;
   arrayOfLong[0] = l;
   int j = localDataInputStream.readInt();
   if (j > System.currentTimeMillis() / 1000L) {
     localDataInputStream.close();
     return arrayOfLong;
   }
   arrayOfLong[1] = j;
   localDataInputStream.close();
   return arrayOfLong;
 }
Exemplo n.º 7
1
  /**
   * Reads the payload of a tag, given the name and type.
   *
   * @param type The type.
   * @param name The name.
   * @param depth The depth.
   * @return The tag.
   * @throws IOException if an I/O error occurs.
   */
  private Tag readTagPayload(int type, String name, int depth) throws IOException {
    switch (type) {
      case NBTConstants.TYPE_END:
        if (depth == 0) {
          throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
        } else {
          return new EndTag();
        }
      case NBTConstants.TYPE_BYTE:
        return new ByteTag(name, is.readByte());
      case NBTConstants.TYPE_SHORT:
        return new ShortTag(name, is.readShort());
      case NBTConstants.TYPE_INT:
        return new IntTag(name, is.readInt());
      case NBTConstants.TYPE_LONG:
        return new LongTag(name, is.readLong());
      case NBTConstants.TYPE_FLOAT:
        return new FloatTag(name, is.readFloat());
      case NBTConstants.TYPE_DOUBLE:
        return new DoubleTag(name, is.readDouble());
      case NBTConstants.TYPE_BYTE_ARRAY:
        int length = is.readInt();
        byte[] bytes = new byte[length];
        is.readFully(bytes);
        return new ByteArrayTag(name, bytes);
      case NBTConstants.TYPE_STRING:
        length = is.readShort();
        bytes = new byte[length];
        is.readFully(bytes);
        return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
      case NBTConstants.TYPE_LIST:
        int childType = is.readByte();
        length = is.readInt();

        List<Tag> tagList = new ArrayList<Tag>();
        for (int i = 0; i < length; i++) {
          Tag tag = readTagPayload(childType, "", depth + 1);
          if (tag instanceof EndTag) {
            throw new IOException("TAG_End not permitted in a list.");
          }
          tagList.add(tag);
        }

        return new ListTag(name, NBTUtils.getTypeClass(childType), tagList);
      case NBTConstants.TYPE_COMPOUND:
        Map<String, Tag> tagMap = new HashMap<String, Tag>();
        while (true) {
          Tag tag = readTag(depth + 1);
          if (tag instanceof EndTag) {
            break;
          } else {
            tagMap.put(tag.getName(), tag);
          }
        }

        return new CompoundTag(name, tagMap);
      default:
        throw new IOException("Invalid tag type: " + type + ".");
    }
  }
 /** Abstract. Reads the raw packet data from the data stream. */
 public void readPacketData(DataInputStream par1DataInputStream) throws IOException {
   xPosition = par1DataInputStream.readInt();
   yPosition = par1DataInputStream.read();
   zPosition = par1DataInputStream.readInt();
   type = par1DataInputStream.read();
   metadata = par1DataInputStream.read();
 }
Exemplo n.º 9
0
 /**
  * Loads a <code>DecisionState</code> object from the given input stream.
  *
  * @param dis the data input stream
  * @return a newly constructed decision state
  * @throws IOException if an error occurs
  */
 public static State loadBinary(DataInputStream dis) throws IOException {
   int index = dis.readInt();
   char c = dis.readChar();
   int qtrue = dis.readInt();
   int qfalse = dis.readInt();
   return new DecisionState(index, c, qtrue, qfalse);
 }
 public void func_73267_a(DataInputStream p_73267_1_) throws IOException {
   this.field_73342_e = p_73267_1_.read();
   this.field_73345_a = p_73267_1_.readInt();
   this.field_73343_b = p_73267_1_.read();
   this.field_73344_c = p_73267_1_.readInt();
   this.field_73341_d = p_73267_1_.read();
 }
Exemplo n.º 11
0
  public void handlePacket(Packet250CustomPayload packet) throws IOException {

    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data));

    byte type = dis.readByte();

    World world = net.minecraft.client.Minecraft.getMinecraft().theWorld;

    ISyncHandler handler = null;

    if (type == TYPE_TILE) {
      int x = dis.readInt();
      int y = dis.readInt();
      int z = dis.readInt();
      if (world != null) {
        if (world.blockExists(x, y, z)) {
          TileEntity tile = world.getBlockTileEntity(x, y, z);
          if (tile instanceof ISyncHandler) {
            handler = (ISyncHandler) tile;
          }
        }
      }
    } else if (type == TYPE_ENTITY) {
      int entityId = dis.readInt();
      Entity entity = world.getEntityByID(entityId);
      if (entity != null && entity instanceof ISyncHandler) {
        handler = (ISyncHandler) entity;
      }
    }
    if (handler != null) {
      List<ISyncableObject> changes = handler.getSyncMap().readFromStream(dis);
      handler.onSynced(changes);
    }
    dis.close();
  }
Exemplo n.º 12
0
 public void load() {
   try {
     InputStream is = new BufferedInputStream(mContext.openFileInput(FILE_NAME), 8192);
     DataInputStream in = new DataInputStream(is);
     int version = in.readInt();
     if (version > LAST_VERSION) {
       throw new IOException("data version " + version + "; expected " + LAST_VERSION);
     }
     if (version > 1) {
       mDeleteMode = in.readInt();
     }
     if (version > 2) {
       int quickSerializable = in.readInt();
       for (Base m : Base.values()) {
         if (m.getQuickSerializable() == quickSerializable) this.mMode = m;
       }
     }
     mHistory = new History(version, in);
     in.close();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 /** Abstract. Reads the raw packet data from the data stream. */
 public void readPacketData(DataInputStream par1DataInputStream) throws IOException {
   sfxID = par1DataInputStream.readInt();
   posX = par1DataInputStream.readInt();
   posY = par1DataInputStream.readByte() & 0xff;
   posZ = par1DataInputStream.readInt();
   auxData = par1DataInputStream.readInt();
 }
Exemplo n.º 14
0
  public final void read(DataInputStream dis) throws IOException {

    int l = dis.readInt();

    forms = new String[l];
    lemmas = new String[l];
    plemmas = new String[l];
    ppos = new String[l];
    gpos = new String[l];
    labels = new String[l];
    heads = new int[l];
    fillp = new String[l];
    ofeats = new String[l];

    for (int k = 0; k < l; k++) {
      forms[k] = dis.readUTF();
      ppos[k] = dis.readUTF();
      gpos[k] = dis.readUTF();
      heads[k] = dis.readInt();
      labels[k] = dis.readUTF();
      lemmas[k] = dis.readUTF();
      plemmas[k] = dis.readUTF();
      ofeats[k] = dis.readUTF();
      fillp[k] = dis.readUTF();
    }
  }
 public void a(DataInputStream paramDataInputStream) {
   this.a = paramDataInputStream.readInt();
   this.e = paramDataInputStream.readByte();
   this.b = paramDataInputStream.readInt();
   this.c = paramDataInputStream.readByte();
   this.d = paramDataInputStream.readInt();
 }
Exemplo n.º 16
0
  /**
   * fill this VoxelSelection using the serialised VoxelSelection byte array
   *
   * @param byteArrayInputStream the bytearray containing the serialised VoxelSelection
   * @return true for success, false for failure (leaves selection untouched)
   */
  public boolean readFromBytes(ByteArrayInputStream byteArrayInputStream) {
    try {
      DataInputStream inputStream = new DataInputStream(byteArrayInputStream);

      int newXsize = inputStream.readInt();
      int newYsize = inputStream.readInt();
      int newZsize = inputStream.readInt();
      if (newXsize < 1
          || newXsize > MAX_X_SIZE
          || newYsize < 1
          || newYsize > MAX_Y_SIZE
          || newZsize < 1
          || newZsize > MAX_Z_SIZE) {
        return false;
      }

      ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
      Object newVoxels = objectInputStream.readObject();
      if (!(newVoxels instanceof BitSet)) return false;
      xSize = newXsize;
      ySize = newYsize;
      zSize = newZsize;
      voxels = (BitSet) newVoxels;
    } catch (ClassNotFoundException cnfe) {
      ErrorLog.defaultLog().debug("Exception while VoxelSelection.readFromDataArray: " + cnfe);
      return false;
    } catch (IOException ioe) {
      ErrorLog.defaultLog().debug("Exception while VoxelSelection.readFromDataArray: " + ioe);
      return false;
    }
    return true;
  }
Exemplo n.º 17
0
 /*     */ private void readData(InputStream paramInputStream) throws IOException /*     */ {
   /*  68 */ DataInputStream localDataInputStream = new DataInputStream(paramInputStream);
   /*     */
   /*  71 */ ICUBinary.readHeader(localDataInputStream, FMT, new IsAcceptable(null));
   /*     */
   /*  75 */ int j = localDataInputStream.readInt();
   /*  76 */ if (j < 0) {
     /*  77 */ throw new IOException("indexes[0] too small in /sun/text/resources/ubidi.icu");
     /*     */ }
   /*  79 */ this.indexes = new int[j];
   /*     */
   /*  81 */ this.indexes[0] = j;
   /*  82 */ for (int i = 1; i < j; i++) {
     /*  83 */ this.indexes[i] = localDataInputStream.readInt();
     /*     */ }
   /*     */
   /*  87 */ this.trie = new CharTrie(localDataInputStream, null);
   /*     */
   /*  90 */ j = this.indexes[3];
   /*  91 */ if (j > 0) {
     /*  92 */ this.mirrors = new int[j];
     /*  93 */ for (i = 0; i < j; i++) {
       /*  94 */ this.mirrors[i] = localDataInputStream.readInt();
       /*     */ }
     /*     */
     /*     */ }
   /*     */
   /*  99 */ j = this.indexes[5] - this.indexes[4];
   /* 100 */ this.jgArray = new byte[j];
   /* 101 */ for (i = 0; i < j; i++) /* 102 */ this.jgArray[i] = localDataInputStream.readByte();
   /*     */ }
Exemplo n.º 18
0
  // Returns important image data to the main class
  @Override
  public ImageData getImages(int limit) {
    try {
      DataInputStream imgInputStream = new DataInputStream(new FileInputStream(imageFilePath));
      imgInputStream.readInt(); // magic number
      int numImgs = imgInputStream.readInt();
      if (limit >= 0 && limit <= numImgs) numImgs = limit;
      int numRows = imgInputStream.readInt();
      int numCols = imgInputStream.readInt();

      // Reduces each image pixel to its grayscale value for processing by the neural network
      double[][] images = new double[numImgs][numRows * numCols];
      for (int i = 0; i < images.length; i++) {
        for (int j = 0; j < images[i].length; j++) {
          images[i][j] = imgInputStream.readUnsignedByte() / 255.0;
        }
      }
      imgInputStream.close();

      return new ImageData(images, numRows, numCols);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
  @Override
  public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data));
    try {
      if ("ModConfig".equals(packet.channel)) {

        int mode = dis.readInt();
        if (mode == 0) {
          String modid = dis.readUTF();
          int entryCount = dis.readInt();
          int pos = 0;
          ConfigMod.dbg("modconfig packet, size: " + entryCount);
          // require a full resync of data, make sure other side sends it all
          if (!GuiConfigEditor.clientMode
              || ConfigMod.configLookup.get(modid).configData.size() == 0) {
            ConfigMod.configLookup.get(modid).configData.clear();
            for (int i = 0; i < entryCount; i++) {
              String str1 = dis.readUTF();
              String str2 = dis.readUTF();
              String str3 = ""; // dis.readUTF();
              ConfigMod.configLookup
                  .get(modid)
                  .configData
                  .add(new ConfigEntryInfo(pos++, str1, str2, str3));
            }
          }
        } else {
          openConfigGui();
        }
      }
    } catch (Exception ex) {
      // HostileWorlds.dbg("ERROR HANDLING HW PACKETS");
      ex.printStackTrace();
    }
  }
Exemplo n.º 20
0
 // returns true if the program crashed in a previous run
 // or false if the program was manually stopped or never interrupted
 private boolean restoreState(String typeOfInterruption) {
   java.io.File file = new File(restoreFilePath + restoreFileName);
   try {
     if (file.exists()) {
       //				System.out.println(">> Restoring system's state " + file.getName() + "...");
       DataInputStream stream = new DataInputStream(new FileInputStream(file));
       collectionCurIndex = stream.readInt();
       heuristicCurIndex = stream.readInt();
       modelCurIndex = stream.readInt();
       System.out.println(
           ">> Indexes restored: [collection="
               + collectionCurIndex
               + ", heuristic="
               + heuristicCurIndex
               + ", model="
               + modelCurIndex
               + "]");
       stream.close();
       if (typeOfInterruption.compareToIgnoreCase("manual-stop") == 0) {
         System.out.println("Type of interruption: Manual");
         return false;
       }
       if (modelCurIndex > collections[collectionCurIndex].size) {
         return false;
       }
       return true;
     }
   } catch (FileNotFoundException e1) {
   } catch (IOException e2) {
     e2.printStackTrace();
   }
   return false;
 }
Exemplo n.º 21
0
  /**
   * Initialize the meterpreter.
   *
   * @param in Input stream to read from
   * @param rawOut Output stream to write into
   * @param loadExtensions Whether to load (as a {@link ClassLoader} would do) the extension jars;
   *     disable this if you want to use your debugger's edit-and-continue feature or if you do not
   *     want to update the jars after each build
   * @param redirectErrors Whether to redirect errors to the internal error buffer; disable this to
   *     see the errors on the victim's standard error stream
   * @param beginExecution Whether to begin executing immediately
   * @throws Exception
   */
  public Meterpreter(
      DataInputStream in,
      OutputStream rawOut,
      boolean loadExtensions,
      boolean redirectErrors,
      boolean beginExecution)
      throws Exception {

    int configLen = in.readInt();
    byte[] configBytes = new byte[configLen];
    in.readFully(configBytes);

    loadConfiguration(in, rawOut, configBytes);

    // after the configuration block is a 32 bit integer that tells us
    // how many stages were wired into the payload. We need to stash this
    // because in the case of TCP comms, we need to skip this number of
    // blocks down the track when we reconnect. We have to store this in
    // the meterpreter class instead of the TCP comms class though
    this.ignoreBlocks = in.readInt();

    this.loadExtensions = loadExtensions;
    this.commandManager = new CommandManager();
    this.channels.add(null); // main communication channel?
    if (redirectErrors) {
      errBuffer = new ByteArrayOutputStream();
      err = new PrintStream(errBuffer);
    } else {
      errBuffer = null;
      err = System.err;
    }
    if (beginExecution) {
      startExecuting();
    }
  }
Exemplo n.º 22
0
  public void readRS() {
    RecordStore rs = null;
    try {
      rs = RecordStore.openRecordStore("score", true);
      byte[] byteA = new byte[100];

      list.removeAllElements();
      // System.out.println("size of list before reading out of rs: "+ list.size());
      for (int i = 1; i < 6; i++) {
        byteA = rs.getRecord(i);
        // System.out.println((char) byteA[0]);
        // System.out.println("1");
        ByteArrayInputStream bytes = new ByteArrayInputStream(byteA);
        // System.out.println("2");
        DataInputStream dataIn = new DataInputStream(bytes);
        // System.out.println("3");
        try {
          list.addElement(
              new ScoreItem(
                  dataIn.readUTF(), dataIn.readInt(), dataIn.readInt(), dataIn.readLong()));
        } catch (IOException exp) {
        }
      }
      // System.out.println("size of list after reading out of rs: "+ list.size());
      rs.closeRecordStore();
    } catch (RecordStoreException exp) {
      System.out.println("fehler: " + exp.toString());
      exp.printStackTrace();
    }
  }
 public void func_73267_a(DataInputStream p_73267_1_) throws IOException {
   field_73329_a = p_73267_1_.readInt();
   field_73327_b = p_73267_1_.readInt();
   field_73328_c = p_73267_1_.readInt();
   field_73325_d = p_73267_1_.readInt();
   field_73326_e = p_73267_1_.read();
 }
Exemplo n.º 24
0
  private static void getMedicineList(Socket socket) {
    int medicineID;
    String medicineName;
    String medicineUnit;
    double price;

    try {
      OutputStream output = socket.getOutputStream();
      DataOutputStream dos = new DataOutputStream(output);
      InputStream input = socket.getInputStream();
      DataInputStream dis = new DataInputStream(input);

      dos.writeInt(8);

      int numberOfMedicine = dis.readInt();

      for (int i = 0; i < numberOfMedicine; i++) {
        medicineID = dis.readInt();
        medicineName = dis.readUTF();
        medicineUnit = dis.readUTF();
        price = dis.readDouble();

        medicineList.add(new Medicine(medicineID, medicineName, medicineUnit, price));
      }

    } catch (IOException e) {
      System.out.println("Cannot get IO streams.");
    }
  }
Exemplo n.º 25
0
 private void readTrack(DataInputStream dataInputStream, Track track)
     throws InvalidMidiDataException, IOException {
   // search for a "MTrk" chunk
   while (true) {
     int nMagic = dataInputStream.readInt();
     if (nMagic == MidiConstants.TRACK_MAGIC) {
       break;
     }
     int nChunkLength = dataInputStream.readInt();
     if (nChunkLength % 2 != 0) {
       nChunkLength++;
     }
     dataInputStream.skip(nChunkLength);
   }
   int nTrackChunkLength = dataInputStream.readInt();
   long lTicks = 0;
   long[] alRemainingBytes = new long[1];
   alRemainingBytes[0] = nTrackChunkLength;
   int[] anRunningStatusByte = new int[1];
   // indicates no running status in effect
   anRunningStatusByte[0] = -1;
   while (alRemainingBytes[0] > 0) {
     long lDeltaTicks = readVariableLengthQuantity(dataInputStream, alRemainingBytes);
     // TDebug.out("delta ticks: " + lDeltaTicks);
     lTicks += lDeltaTicks;
     MidiEvent event = readEvent(dataInputStream, alRemainingBytes, anRunningStatusByte, lTicks);
     track.add(event);
   }
 }
Exemplo n.º 26
0
  @Override
  public void load() throws Exception {
    File file = Game.getInstance().getRelativeFile(Game.FILE_BASE_USER_DATA, "${world}/world.dat");

    if (!file.exists()) {
      System.err.println("No level data found! " + file.getPath());
      return;
    }

    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));

    _world.setTime(dis.readFloat());

    _spawnPoint = new Vec3f();
    IOUtilities.readVec3f(dis, _spawnPoint);

    readDataPointList(dis, _rawHeights);
    readDataPointList(dis, _heights);
    readDataPointList(dis, _humidities);
    readDataPointList(dis, _temperatures);

    /* Tree Definitions */
    {
      int size = dis.readInt();
      for (int i = 0; i < size; ++i) {
        TreeDefinition dp2d = new TreeDefinition(0, 0, 0, 0);
        dp2d.x = dis.readInt();
        dp2d.y = dis.readInt();
        dp2d.z = dis.readInt();
        dp2d.type = dis.readByte();
      }
    }

    dis.close();
  }
Exemplo n.º 27
0
  public static ArrayList<Patient> getPatientList(Socket socket, ArrayList<Patient> patientList) {
    int id;
    String ic;
    String fname;
    String lname;
    int age;
    int cnumber;

    try {
      OutputStream output = socket.getOutputStream();
      DataOutputStream dos = new DataOutputStream(output);
      InputStream input = socket.getInputStream();
      DataInputStream dis = new DataInputStream(input);

      dos.writeInt(2);

      int numberOfPatients = dis.readInt();

      for (int i = 0; i < numberOfPatients; i++) {
        id = dis.readInt();
        ic = dis.readUTF();
        fname = dis.readUTF();
        lname = dis.readUTF();
        age = dis.readInt();
        cnumber = dis.readInt();

        patientList.add(new Patient(id, ic, fname, lname, age, cnumber));
      }

    } catch (IOException e) {
      System.out.println("Cannot get IO streams.");
    }

    return patientList;
  }
  /**
   * Método auxiliar que gerar uma Coleção de Dados da Movimentação
   *
   * @param data
   * @return
   * @throws IOException
   */
  private Collection<DadosMovimentacao> gerarColecaoDadosMovimentacao(
      DataInputStream data, Long imei) throws IOException {
    Collection<DadosMovimentacao> dados = new ArrayList<DadosMovimentacao>();
    int imovel = data.read();
    while (imovel != -1) {

      byte[] b = new byte[4];
      b[0] = (byte) imovel;
      b[1] = (byte) data.read();
      b[2] = (byte) data.read();
      b[3] = (byte) data.read();

      dados.add(
          new DadosMovimentacao(
              new Integer(this.convertArrayByteToInt(b)),
              new Integer(data.readInt()),
              new Integer(data.readByte()),
              new Date(data.readLong()),
              imei,
              new Byte(data.readByte()),
              new Integer(data.readInt())));

      // System.out.println("imovel=" + data.read());
      imovel = data.read();
    }
    return dados;
  }
Exemplo n.º 29
0
  @Override
  public void run() {
    while (true)
      try {
        switch (inputStream.readUTF()) {
          case "GetAllEdges":
            level = inputStream.readInt();
            GetAllEdges();
            break;

          case "GetEdges":
            level = inputStream.readInt();
            GetEdges();
            break;

          case "ChangeZoomLevel":
            zoom = inputStream.readDouble();
            offset = (kpSize - zoom) / 2;
            GetEdges();
            break;
        }
      } catch (IOException e) {
        e.printStackTrace();
        break;
      }
  }
Exemplo n.º 30
0
  private Message parseMessage(byte[] data) {

    Message result = new Message();
    try {
      ByteArrayInputStream bais = new ByteArrayInputStream(data);
      DataInputStream dis = new DataInputStream(new BufferedInputStream(bais));
      int cmdCount = dis.readInt();
      byte[] cmdBytes = new byte[cmdCount];
      dis.read(cmdBytes);
      String cmd = new String(cmdBytes);
      result.setCommand(cmd);

      if (cmd.equalsIgnoreCase("CALC")) {

        int valuesCount = dis.readInt();
        byte[] valuesBytes = new byte[valuesCount];
        dis.read(valuesBytes);
        String[] values = new String(valuesBytes).split("\0");
        for (String v : values) {
          String[] s = v.split("=");
          result.addValue(s[0], s[1]);
        }
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    return result;
  }