There is an existing api which writes the file to particular location and the code snippet is like below:
long lastUpdatedOn = System.currentTimeMillis();
try(BufferedOutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(filePath, true))) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
long now = System.currentTimeMillis();
if (now - lastUpdatedOn > 2 * 1000L) {
fileOutputStream.flush();
lastUpdatedOn = now;
}
}
It is running in background. I want to have api(will hit on certain interval) which should return the real-time size of the file. Suppose filesize is 1GB. If 500MB file content is written at the moment when I hit the api then it should return that file-size. I have code like below:
java.nio.file.Path path = Paths.get(destinationFullFolderPath.toString());
if (Files.exists(path)) {
resultMap.put(fileName, Files.size(path));
}
But I am constantly hitting this api and getting empty result and I get the result once total file is written. I am confused that where should I make change. Whether to make change in the api which is writing file or in the api which should return real-time filesize.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743965839a4537521.html
评论列表(0条)