byte actionAsByte = connection.readByte();
try {
Action action = Action.values()[actionAsByte];
if (action == Action.INPUT_STREAM) {
String relPath = connection.readString();
VirtualFile file = virtualFileService.getRootDirectory().getFile(relPath);
if (file.exists()) {
InputStream is = file.createInputStream();
connection.writeLong(LONG_OK);
IOUtils.copy(is, connection.getOs());
connection.flush();
} else {
connection.writeLong(LONG_ERROR);
connection.writeString("Could not find file " + relPath);
connection.flush();
}
} else if (action == Action.OUTPUT_STREAM) {
String relPath = connection.readString();
VirtualFile file = virtualFileService.getRootDirectory().getFile(relPath);
OutputStream os = file.createOutputStream();
connection.writeLong(LONG_OK);
connection.flush();
IOUtils.copy(connection.getIs(), os);
} else if (action == Action.EXISTS) {
String relPath = connection.readString();
VirtualFile file = virtualFileService.getRootDirectory().getFile(relPath);
connection.writeBoolean(file.exists());
connection.flush();
} else {
connection.writeLong(LONG_ERROR);
connection.writeString("Unknown command " + action);
connection.flush();