EcClientLibUtil.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package epson.print.ecclient;
  2. import java.io.File;
  3. import java.util.regex.Pattern;
  4. public class EcClientLibUtil {
  5. public static final int CREATE_JOB_NAME_MAX_LENGTH = 256;
  6. public static String quoteForJsonString(String str) {
  7. if (str == null) {
  8. return null;
  9. }
  10. return Pattern.compile("([\"\\\\])").matcher(str).replaceAll("\\\\$1");
  11. }
  12. public static String getCreateJobFileName(int i, String str) throws IllegalArgumentException {
  13. if (str == null) {
  14. return null;
  15. }
  16. File file = new File(str);
  17. switch (i) {
  18. case 1:
  19. str = file.getName();
  20. if (str.length() > 256) {
  21. throw new IllegalArgumentException();
  22. }
  23. break;
  24. case 2:
  25. str = file.getName();
  26. break;
  27. case 3:
  28. break;
  29. default:
  30. return null;
  31. }
  32. if (str.length() > 256) {
  33. str = str.substring(0, 256);
  34. }
  35. return quoteForJsonString(str);
  36. }
  37. }