We have one SFTP server where we placed one file present in ./test/directory1/test.csv.
We added one custom attribute to this file before placing it to this directory , attribute name "user.customchecksum", below is code which we used to add attribute
Path file = Paths.get("C:/Files/test.csv");
UserDefinedFileAttributeView view = Files.getFileAttributeView(file,
UserDefinedFileAttributeView.class);
view.write("user.customchecksum", Charset.defaultCharset().encode("XDRSECTVVTEST"));
Now before downloading this file we want to check that this attribute value and after that only we download this file.
Note::
For connection we are using JSCH and able to get File Inputstream without downloading the file.
Below method we are using to read file attribute value after file is downloaded.
But now we want to read this attribute before downloading file.
private void getCustomAttributes(String filePath) {
try {
Path file = Paths.get(filePath);
UserDefinedFileAttributeView view = Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
String name = "user.customchecksum";
ByteBuffer buf = ByteBuffer.allocate(view.size(name));
view.read(name, buf);
buf.flip();
String value = Charset.defaultCharset().decode(buf).toString();
} catch (IOException e) {
e.printStackTrace();
}
}
We are able to read file InputStream before downloading file, can this be used to read added attributes? if yes what is the way to do this?