Created
September 4, 2017 20:48
-
-
Save ipapaste/d7350cd071e72ab01800b8b0d076c8cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Result<FileDto> getFromFile(File f) { | |
Result<FileDto> result = new Result<>(); | |
FileDto dto = new FileDto(); | |
dto.setName(f.getName()); | |
dto.setPath(f.getAbsolutePath()); | |
dto.setDirectory(f.isDirectory()); | |
dto.setSize(f.length()); | |
dto.setModifiedAt(f.lastModified()); | |
try { | |
BasicFileAttributes attr = Files.readAttributes(f.toPath(), BasicFileAttributes.class); | |
dto.setCreatedAt(attr.creationTime().toMillis()); | |
} | |
catch(Exception e) | |
{ | |
result.setIncomplete(true); | |
result.getReasons().add(new Exception("Unable to transform " +f.getAbsolutePath() + " to DTO.", e)); | |
} | |
return result; | |
} | |
public static class Result<T> | |
{ | |
T result; | |
boolean incomplete; | |
List<Exception> reasons = new ArrayList<>(); | |
public T getResult() { | |
return result; | |
} | |
public void setResult(T result) { | |
this.result = result; | |
} | |
public boolean isIncomplete() { | |
return incomplete; | |
} | |
public void setIncomplete(boolean incomplete) { | |
this.incomplete = incomplete; | |
} | |
public List<Exception> getReasons() { | |
return reasons; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment