@Test(expected = NotfoundException.class) public void testFindNotFound() throws Exception { new SFTPAttributesFinderFeature(session).find(new Path(UUID.randomUUID().toString(), EnumSet.of(Path.Type.file))); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
SFTPAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } }
SFTPAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SFTPAttributesFinderFeature(final SFTPSession session); }
SFTPAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SFTPAttributesFinderFeature(final SFTPSession session); @Override PathAttributes find(final Path file); PathAttributes toAttributes(final FileAttributes stat); }
SFTPAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SFTPAttributesFinderFeature(final SFTPSession session); @Override PathAttributes find(final Path file); PathAttributes toAttributes(final FileAttributes stat);  }