각 행에서 다중 바이트 배열을 추가한다는 것은 모든 변수를 변수에 추가해야한다는 의미입니다. 그러나 이것은 변경할 수 없으므로 빈 바이트 배열을 인쇄합니다. 더 많은 바이트를 추가하려면 어떻게해야합니까?다중 바이트 배열 추가
ResultSet rs = stmt.executeQuery(query);
int matchesLength = 0;
try {
boolean b = rs.last();
if (b) {
matchesLength = rs.getRow();
}
}
catch (SQLException e) {
e.printStackTrace();
}
byte[] matches = new byte[118 * matchesLength];
while (rs.next()) {
String matchId = rs.getString("id");
String matchTitle = rs.getString("title");
String matchDescription = rs.getString("description");
int matchPlayers = rs.getInt("max_players");
int matchMaxPlayers = rs.getInt("max_players");
String matchHostId = rs.getString("host_id");
short matchPlayersShort = (short) matchPlayers;
byte[] matchPlayersBytes = ByteBuffer.allocate(2).putShort(matchPlayersShort).array();
short matchMaxPlayersShort = (short) matchMaxPlayers;
byte[] matchMaxPlayersBytes = ByteBuffer.allocate(2).putShort(matchMaxPlayersShort).array();
byte[][] match = {
String.format("%1$-" + 32 + "s", matchId).getBytes(),
String.format("%1$-" + 22 + "s", matchTitle).getBytes(),
String.format("%1$-" + 44 + "s", matchDescription).getBytes(),
matchPlayersBytes,
matchMaxPlayersBytes,
String.format("%1$-" + 16 + "s", matchHostId).getBytes()
};
// global offset variable, for each array copy
combineBytes(match, matches);
}
'combineBytes'는 무엇을합니까? – SubOptimal
@SubOptimal "match"의 모든 배열에 대해 배열 복사를 사용하여 "matches"에 배열을 추가하고 오프셋을 증가시킵니다. (오프셋은 전역 변수이므로 0으로 재설정되지 않습니다.) – Kenny
[ByteArrayOutputStream] (http://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayOutputStream.html)을 사용해야 할 수도 있습니다.). 이렇게하면 "동적 인"bytearray를 가질 수 있습니다. – Flown