private void getChildFiles(final File base, final List<File> childFiles) { for (File child : base.listFiles()) { childFiles.add(child); if (child.isFile() || isEmpty(child)) { childFiles.add(child); } else { getChildFiles(child, childFiles); } } }
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 List<File> getChildFiles(final File base) { final List<File> childFiles = new ArrayList<>(); getChildFiles(base, childFiles); return childFiles; }
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 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 List<File> getChildFiles(final File base) { final List<File> childFiles = new ArrayList<File>(); getChildFiles(base, childFiles); return childFiles; }
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 getChildFiles(final File base, final List<File> childFiles) { for (File child : base.listFiles()) { if (child.isFile()) { childFiles.add(child); } else { getChildFiles(child, childFiles); } } }