You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

8 years ago
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.highcharts.export.util;
  6. import java.io.IOException;
  7. import java.nio.file.Files;
  8. import java.nio.file.Path;
  9. import java.nio.file.Paths;
  10. import org.apache.commons.io.FileUtils;
  11. import org.apache.commons.io.FilenameUtils;
  12. import org.apache.log4j.Logger;
  13. /**
  14. *
  15. * @author gert
  16. */
  17. public class TempDir {
  18. public static Path tmpDir;
  19. public static Path outputDir;
  20. public static Path phantomJsDir;
  21. protected static Logger logger = Logger.getLogger(TempDir.class.getName());
  22. public TempDir() throws IOException {
  23. tmpDir = Files.createTempDirectory("export");
  24. // Delete this directory on deletion of the JVM
  25. tmpDir.toFile().deleteOnExit();
  26. outputDir = Files.createDirectory(Paths.get(tmpDir.toString(), "output"));
  27. outputDir.toFile().deleteOnExit();
  28. phantomJsDir = Files.createDirectory(Paths.get(tmpDir.toString(), "phantomjs"));
  29. phantomJsDir.toFile().deleteOnExit();
  30. Runtime.getRuntime().addShutdownHook(new Thread() {
  31. @Override
  32. public void run() {
  33. FileUtils.deleteQuietly(tmpDir.toFile());
  34. }
  35. });
  36. logger.debug("Highcharts Export Server using " +TempDir.getTmpDir() + " as TEMP folder.");
  37. }
  38. public static Path getTmpDir() {
  39. return tmpDir;
  40. }
  41. public static Path getOutputDir() {
  42. return outputDir;
  43. }
  44. public static Path getPhantomJsDir() {
  45. return phantomJsDir;
  46. }
  47. public static String getDownloadLink(String filename) {
  48. filename = FilenameUtils.getName(filename);
  49. String link = "files/" + filename;
  50. return link;
  51. }
  52. }