Guest User

Untitled

a guest
Apr 1st, 2019
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.groupdocs.comparison.examples;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.nio.file.FileSystems;
  7. import java.nio.file.Path;
  8. import java.util.Properties;
  9.  
  10. import com.groupdocs.comparison.common.license.License;
  11. import com.groupdocs.comparison.common.license.Metered;
  12. //ExStart:commonutilitiesclass
  13. public class Utilities {
  14.  
  15. // ExStart:CommonProperties
  16.  
  17. public final static String sourcePath = "./Data/SourceFiles/";
  18. public final static String targetPath = "./Data/TargetFiles/";
  19. public static final Path resultFilePath = getProjectBaseDir().resolve("Data/ResultFiles/output");
  20. public final static String resultFile = "result";
  21. public static final Path licensePath = getProjectBaseDir().resolve("GroupDocs.Comparison.lic");
  22. public final static String sourcePassword = "pass";
  23. public final static String targetPassword = "pass";
  24. public static String outputFileName(String extension) {
  25. String resultPath = resultFilePath + extension;
  26. return resultPath;
  27. }
  28. // ExEnd:CommonProperties
  29.  
  30. /**
  31. * This method applies product license from file
  32. *
  33. */
  34. public static void applyLicenseFromFile() {
  35. //ExStart:applyLicenseFromFile
  36. try {
  37. // Setup license
  38. License lic = new License();
  39. System.out.println("Lisence Path: " + licensePath);
  40. lic.setLicense(licensePath.toString());
  41. if(lic.isValidLicense()){
  42. System.out.println("License is validated");
  43. }
  44. } catch (Exception exp) {
  45. System.out.println("Exception: " + exp.getMessage());
  46. exp.printStackTrace();
  47. }
  48. //ExEnd:applyLicenseFromFile
  49. }
  50. /*
  51. * get project base directories
  52. */
  53. public static Path getProjectBaseDir() {
  54. Properties props = new Properties();
  55. try {
  56. InputStream i = Utilities.class.getResourceAsStream("/project.properties");
  57. props.load(i);
  58. } catch (IOException x) {
  59. throw new RuntimeException(x);
  60. }
  61. return FileSystems.getDefault().getPath(props.getProperty("project.basedir"));
  62. }
  63. /**
  64. * This method applies product license from stream
  65. *
  66. */
  67. public static void applyLicenseFromStream(String filePath) {
  68. // ExStart:ApplyLicenseFromStreamObj
  69. try {
  70. // Obtain license stream
  71. FileInputStream licenseStream = new FileInputStream(filePath);
  72.  
  73. // Setup license
  74. License lic = new License();
  75. lic.setLicense(licenseStream);
  76. } catch (Exception exp) {
  77. System.out.println("Exception: " + exp.getMessage());
  78. exp.printStackTrace();
  79. }
  80. // ExEnd:ApplyLicenseFromStreamObj
  81. }
  82.  
  83. public static void meteredLicense(String filePath) {
  84. // ExStart:meteredLicense
  85. try {
  86. // Obtain license stream
  87. Metered metered = new Metered();
  88. metered.setMeteredKey("****", "****");
  89. } catch (Exception exp) {
  90. System.out.println("Exception: " + exp.getMessage());
  91. exp.printStackTrace();
  92. }
  93. // ExEnd:meteredLicense
  94. }
  95. public static InputStream sourceStream(String sourceFile) throws Throwable {
  96. String sourceFilePath = sourcePath + sourceFile;
  97. InputStream sourceStream = new FileInputStream(sourceFilePath);
  98. return sourceStream;
  99. }
  100. public static InputStream targetStream(String targetFile) throws Throwable {
  101. String targetFilePath = targetPath + targetFile;
  102. InputStream targetStream = new FileInputStream(targetFilePath);
  103. return targetStream;
  104.  
  105. }
  106. }
  107. //ExEnd:commonutilitiesclass
RAW Paste Data