Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. public class FileDetails
  2. {
  3.  
  4. String URL;
  5. String Port;
  6. String UserName;
  7. String Pwd;
  8.  
  9. public String getUserName() {
  10. return UserName;
  11. }
  12.  
  13. public String getPort() {
  14. return Port;
  15. }
  16. public String getPwd() {
  17. return Pwd;
  18. }
  19. public String getURL() {
  20. return URL;
  21. }
  22. public void setPort(String port) {
  23. this.Port = port;
  24. }
  25. public void setPwd(String pwd) {
  26. this.Pwd = pwd;
  27. }
  28. public void setURL(String URL) {
  29. this.URL = URL;
  30. }
  31. public void setUserName(String userName) {
  32. this.UserName = userName;
  33. }
  34. }
  35.  
  36. public class FileService extends FileDetails
  37. {
  38. public FileService(FileDetails fileDetails)
  39. {
  40. FileDetails fileDet = null;
  41.  
  42. ObjectMapper objectMapper = new ObjectMapper();
  43. objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  44. try
  45. {
  46. fileDet = objectMapper.readValue(new File("res.json"), fileDetails.class);
  47. }
  48. catch(IOException e)
  49. {
  50. e.printStackTrace();
  51. }
  52. if (fileDet != null) {
  53. fileDetails.setUserName(fileDet.getUserName());
  54. fileDetails.setPwd(fileDet.getPwd());
  55. fileDetails.setURL(fileDet.getURL());
  56. fileDetails.setPort(fileDet.getPort());
  57. } else {
  58. System.out.println("Didn't set details");
  59. }
  60. }
  61. }
  62.  
  63. FileDetails fileDetails = new FileDetails();
  64. FileService fileService = new FileService(fileDetails);
  65.  
  66. public class FileDetails {
  67. private String url;
  68. private String port;
  69. private String userName;
  70. private String password;
  71.  
  72. public FileDetails(String url, String port, String userName, String password) {
  73. this.url = url;
  74. this.port = port;
  75. this.userName = userName;
  76. this.password = password;
  77. }
  78.  
  79. public FileDetails(Path detailsFile) {
  80. try (InputStream in = Files.newInputStream(detailsFile, StandardOpenOption.READ)) {
  81. ObjectMapper mapper = new ObjectMapper();
  82. mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  83. FileDetails details = mapper.readValue(in, FileDetails.class);
  84.  
  85. this.url = details.url;
  86. this.port = details.port;
  87. this.userName = details.userName;
  88. this.password = details.password;
  89. } catch (IOException e) {
  90. e.printStackTrace(System.err);
  91. }
  92. }
  93. // getters and setters omitted
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement