errorStream.println("Failed to open the output stream");
e.printStackTrace(errorStream);
}
if(writer != null) {
while(partitionKeys.hasNext()) {
ByteArray keyByteArray = partitionKeys.next();
StringBuilder lineBuilder = new StringBuilder();
lineBuilder.append(ByteUtils.getString(keyByteArray.get(), "UTF-8"));
lineBuilder.append("\n");
writer.write(lineBuilder.toString());
}
writer.flush();
}
} else if(line.toLowerCase().startsWith("fetch")) {
String[] args = line.substring("fetch".length() + 1).split("\\s+");
int remoteNodeId = Integer.valueOf(args[0]);
String storeName = args[1];
List<Integer> partititionList = parseCsv(args[2]);
Iterator<Pair<ByteArray, Versioned<byte[]>>> partitionEntries = adminClient.bulkFetchOps.fetchEntries(remoteNodeId,
storeName,
partititionList,
null,
false);
BufferedWriter writer = null;
try {
if(args.length > 3) {
writer = new BufferedWriter(new FileWriter(new File(args[3])));
} else
writer = new BufferedWriter(new OutputStreamWriter(commandOutput));
} catch(IOException e) {
errorStream.println("Failed to open the output stream");
e.printStackTrace(errorStream);
}
if(writer != null) {
while(partitionEntries.hasNext()) {
Pair<ByteArray, Versioned<byte[]>> pair = partitionEntries.next();
ByteArray keyByteArray = pair.getFirst();
Versioned<byte[]> versioned = pair.getSecond();
StringBuilder lineBuilder = new StringBuilder();
lineBuilder.append(ByteUtils.getString(keyByteArray.get(), "UTF-8"));
lineBuilder.append("\t");
lineBuilder.append(versioned.getVersion());
lineBuilder.append("\t");
lineBuilder.append(ByteUtils.getString(versioned.getValue(), "UTF-8"));
lineBuilder.append("\n");