@Override public String getUsername(byte[] encodedKey) { String b64key = Base64.getEncoder().encodeToString(encodedKey); try { try (PreparedStatement preparedStatement = conn.prepareStatement("select name from users where publickey = ? limit 1")) { preparedStatement.setString(1, b64key); ResultSet resultSet = preparedStatement.executeQuery(); boolean next = resultSet.next(); if (!next) return ""; return resultSet.getString(1); } } catch (SQLException sqle) { throw new IllegalStateException(sqle); } }
@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); } }