@Override public String handleCommand(String aSessionId, String anInput) { if (anInput.startsWith(Command.FILE.name())) { // just get the pipe protocol to make sure it is there and to add the listener to it try { getPipeProtocol(); String theFileName = anInput.substring(Command.FILE.name().length() + 1); if (myFileHandler == null) { return Response.REFUSED.name(); } File theFile = myFileHandler.acceptFile(theFileName); if (theFile == null) { return Response.REFUSED.name(); } FileStatus theStatus = new FileStatus(theFileName, theFile); UUID theUID = UUID.randomUUID(); myMapping.put(theUID, theStatus); return Response.ACCEPTED.name() + " " + theUID.toString(); } catch (ProtocolException e) { return ProtocolContainer.Response.UNKNOWN_PROTOCOL.name(); } } else if (anInput.startsWith(Command.WAIT_FOR_FILE.name())) { String[] theFileAttributes = anInput.split(" "); String theFileId = theFileAttributes[1]; long theFileSize = Long.parseLong(theFileAttributes[2]); UUID theFileUUID = UUID.fromString(theFileId); if (!myMapping.containsKey(theFileUUID)) { return Response.FILE_NOK.name(); } else { try { FileStatus theFileStatus = myMapping.get(theFileUUID); FileStatus.Status theStatus = theFileStatus.waitForStatus(); if (theStatus == FileStatus.Status.OK) { // check the file size long theRealLength = theFileStatus.getFile().length(); if (theRealLength == theFileSize) { return Response.FILE_OK.name(); } else { return Response.BAD_FILE_SIZE.name(); } } else { return Response.FILE_NOK.name(); } } catch (InterruptedException e) { return Response.FILE_NOK.name(); } } } return Response.UNKNOWN_COMMAND.name(); }