示例#1
0
  @Override
  public byte[] getFollowRequests(UserPublicKey owner) {
    byte[] dummy = null;
    FollowRequestData request = new FollowRequestData(owner, dummy);
    RowData[] requests = request.select();
    if (requests == null) return new byte[4];

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutput dout = new DataOutputStream(bout);
    try {
      dout.writeInt(requests.length);
      for (RowData req : requests) Serialize.serialize(req.data, dout);
      return bout.toByteArray();
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
  }
示例#2
0
  @Override
  public byte[] getAllUsernamesGzip() throws IOException {
    try (PreparedStatement stmt = conn.prepareStatement("select name from users")) {
      ResultSet rs = stmt.executeQuery();
      List<String> list = new ArrayList<>();
      while (rs.next()) {
        String username = rs.getString("name");
        list.add(username);
      }

      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      try (DataOutputStream dout = new DataOutputStream(new GZIPOutputStream(bout))) {

        for (String uname : list) Serialize.serialize(uname, dout);
      }
      return bout.toByteArray();
    } catch (SQLException sqe) {
      throw new IOException(sqe);
    }
  }