public void handleResponse(DataInput input, File localPath, BasicLogger log, ActiveOperation.ResultHandler<File> resultHandler, ManagementRequestContext<Void> context) throws IOException, CannotCreateLocalDirectoryException, DidNotReadEntireFileException{ expectHeader(input, protocol.paramNumFiles()); int numFiles = input.readInt(); log.debugf("Received %d files for %s", numFiles, localPath); expectHeader(input, protocol.fileStart()); expectHeader(input, protocol.paramFilePath()); final String path = input.readUTF(); expectHeader(input, protocol.paramFileSize()); final long length = input.readLong(); log.debugf("Received file [%s] of length %d", path, length); expectHeader(input, protocol.fileEnd());
public void handleResponse(DataInput input, File localPath, BasicLogger log, ActiveOperation.ResultHandler<File> resultHandler, ManagementRequestContext<Void> context) throws IOException, CannotCreateLocalDirectoryException, DidNotReadEntireFileException{ expectHeader(input, protocol.paramNumFiles()); int numFiles = input.readInt(); log.debugf("Received %d files for %s", numFiles, localPath); expectHeader(input, protocol.fileStart()); expectHeader(input, protocol.paramFilePath()); final String path = input.readUTF(); expectHeader(input, protocol.paramFileSize()); final long length = input.readLong(); log.debugf("Received file [%s] of length %d", path, length); expectHeader(input, protocol.fileEnd());
public void handleRequest(final DataInput input, final RootFileReader reader, final ActiveOperation.ResultHandler<Void> resultHandler, final ManagementRequestContext<Void> context) throws IOException { expectHeader(input, protocol.paramRootId()); final byte rootId = input.readByte(); expectHeader(input, protocol.paramFilePath()); final String filePath = input.readUTF(); ManagementRequestContext.AsyncTask<Void> task = new ManagementRequestContext.AsyncTask<Void>() { @Override public void execute(ManagementRequestContext<Void> context) throws RequestProcessingException, IOException { final File localPath = reader.readRootFile(rootId, filePath); FlushableDataOutput output = context.writeMessage(ManagementResponseHeader.create(context.getRequestHeader())); try { writeResponse(localPath, output); output.close(); resultHandler.done(null); // call stack (AsyncTaskRunner created by ManagementRequestContext) handles failures } finally { StreamUtils.safeClose(output); } } }; if (asyncExecutor == null) { context.executeAsync(task); } else { context.executeAsync(task, asyncExecutor); } }
public void handleRequest(final DataInput input, final RootFileReader reader, final ManagementRequestContext<Void> context) throws IOException { expectHeader(input, protocol.paramRootId()); final byte rootId = input.readByte(); expectHeader(input, protocol.paramFilePath()); final String filePath = input.readUTF(); ManagementRequestContext.AsyncTask<Void> task = new ManagementRequestContext.AsyncTask<Void>() { @Override public void execute(ManagementRequestContext<Void> context) throws Exception { final File localPath = reader.readRootFile(rootId, filePath); //final FlushableDataOutput output = writeGenericResponseHeader(context); FlushableDataOutput output = context.writeMessage(ManagementResponseHeader.create(context.getRequestHeader())); try { writeResponse(localPath, output); output.close(); } finally { StreamUtils.safeClose(output); } } }; if (asyncExecutor == null) { context.executeAsync(task); } else { context.executeAsync(task, asyncExecutor); } }
private void writeFile(final File localPath, final File file, final FlushableDataOutput output) throws IOException { output.writeByte(protocol.fileStart()); output.writeByte(protocol.paramFilePath()); output.writeUTF(getRelativePath(localPath, file)); output.writeByte(protocol.paramFileSize()); output.writeLong(file.length()); InputStream inputStream = null; try { inputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int len; while ((len = inputStream.read(buffer)) != -1) { output.write(buffer, 0, len); } } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ignored) { } } } output.writeByte(protocol.fileEnd()); }
private void writeFile(final File localPath, final File file, final FlushableDataOutput output) throws IOException { output.writeByte(protocol.fileStart()); output.writeByte(protocol.paramFilePath()); output.writeUTF(getRelativePath(localPath, file)); output.writeByte(protocol.paramFileSize()); if (file.isDirectory()) { output.writeLong(0L); output.writeByte(protocol.fileEnd()); return; } else { output.writeLong(file.length()); } InputStream inputStream = null; try { inputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int len; while ((len = inputStream.read(buffer)) != -1) { output.write(buffer, 0, len); } } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ignored) { } } } output.writeByte(protocol.fileEnd()); }
private void writeResponse(final File localPath, final FlushableDataOutput output) throws IOException { output.writeByte(protocol.paramNumFiles()); if (localPath == null || !localPath.exists()) { output.writeInt(-1); } else if (localPath.isFile()) { output.writeInt(1); writeFile(localPath, localPath, output); } else { final List<File> childFiles = getChildFiles(localPath); output.writeInt(childFiles.size()); for (File child : childFiles) { writeFile(localPath, child, output); } } }
private void writeResponse(final File localPath, final FlushableDataOutput output) throws IOException { output.writeByte(protocol.paramNumFiles()); if (localPath == null || !localPath.exists()) { output.writeInt(-1); } else if (localPath.isFile()) { output.writeInt(1); writeFile(localPath, localPath, output); } else { final List<File> childFiles = getChildFiles(localPath); output.writeInt(childFiles.size()); for (File child : childFiles) { writeFile(localPath, child, output); } } }
public void sendRequest(FlushableDataOutput output, byte rootId, String filePath) throws IOException{ output.writeByte(protocol.paramRootId()); output.writeByte(rootId); output.writeByte(protocol.paramFilePath()); output.writeUTF(filePath); }
public void sendRequest(FlushableDataOutput output, byte rootId, String filePath) throws IOException{ output.writeByte(protocol.paramRootId()); output.writeByte(rootId); output.writeByte(protocol.paramFilePath()); output.writeUTF(filePath); }