labelingsystem-server  Version 0.1.0.0
LSDump Class Reference
Inheritance diagram for LSDump:
Collaboration diagram for LSDump:

Public Member Functions

void run ()
 

Private Member Functions

void writeFile ()
 

Member Function Documentation

◆ run()

void run ( )
22  {
23  if (DumpResource.dumping) {
24  writeFile();
25  }
26  }

References DumpResource.dumping, and LSDump.writeFile().

◆ writeFile()

void writeFile ( )
private
28  {
29  try {
30  // look for file number and delete
31  DumpResource.listDumpFilesDeleteForMax();
32  // create tmp folder
33  File tmpDir1 = new File(DumpResource.tmpDirPath.substring(0, DumpResource.tmpDirPath.length() - 1));
34  if (!tmpDir1.exists()) {
35  if (tmpDir1.mkdir()) {
36  } else {
37  System.out.println("Failed to create directory!");
38  }
39  }
40  File tmpDir2 = new File(DumpResource.tmpDirPath2.substring(0, DumpResource.tmpDirPath2.length() - 1));
41  if (!tmpDir2.exists()) {
42  if (tmpDir2.mkdir()) {
43  } else {
44  System.out.println("Failed to create directory!");
45  }
46  }
47  // download dump
48  URL link = new URL(DumpResource.downloadLink);
49  InputStream in = new BufferedInputStream(link.openStream());
50  ByteArrayOutputStream out = new ByteArrayOutputStream();
51  byte[] buf = new byte[1024];
52  int n = 0;
53  while (-1 != (n = in.read(buf))) {
54  out.write(buf, 0, n);
55  }
56  out.close();
57  in.close();
58  byte[] response2 = out.toByteArray();
59  long currentTime = System.currentTimeMillis();
60  String fileName = DumpResource.tmpDirPath + String.valueOf(currentTime) + ".ttl";
61  FileOutputStream fos = new FileOutputStream(fileName);
62  fos.write(response2);
63  fos.close();
64  // copy file
65  Path sourcePath = Paths.get(fileName);
66  Path destinationpath = Paths.get(fileName.replace(String.valueOf(currentTime), "labelingsystem-latest").replace(DumpResource.tmpDirString, DumpResource.tmpDirString2));
67  Files.copy(sourcePath, destinationpath);
68  // delete file
69  File fileDelete = new File(fileName.replace(String.valueOf(currentTime), "labelingsystem-latest"));
70  Files.deleteIfExists(fileDelete.toPath());
71  // write readme.txt
72  PrintWriter writer = new PrintWriter(DumpResource.tmpDirPath + "readme.txt", "UTF-8");
73  writer.println("Labeling System Readme");
74  writer.close();
75  PrintWriter writer2 = new PrintWriter(DumpResource.tmpDirPath2 + "readme.txt", "UTF-8");
76  writer2.println("Labeling System Readme");
77  writer2.close();
78  // compress folder(s)
79  DumpResource.dumbNo++;
80  String compressedFile = DumpResource.fileDir + "LS-" + String.valueOf(currentTime) + "-" + DumpResource.getNumberOfStatements() + "-" + DumpResource.dumbNo + ".tar.gz"; // destination tar.gz
81  TarGZ.compressWithoutFolder(DumpResource.tmpDirPath, compressedFile, DumpResource.tmpDirString);
82  String compressedFile2 = DumpResource.fileDir + "labelingsystem-latest.tar.gz"; // destination tar.gz
83  TarGZ.compressWithoutFolder(DumpResource.tmpDirPath2, compressedFile2, DumpResource.tmpDirString2);
84  // delte tmp folder(2)
85  FileUtils.deleteDirectory(new File(DumpResource.tmpDirPath));
86  FileUtils.deleteDirectory(new File(DumpResource.tmpDirPath2));
87  // set public path
88  DumpResource.lastDump = DumpResource.filePath + "LS-" + String.valueOf(currentTime) + "-" + DumpResource.getNumberOfStatements() + "-" + DumpResource.dumbNo + ".tar.gz"; // destination tar.gz
89  // sleep and start function again
90  SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");
91  Date resultdate = new Date(currentTime);
92  System.out.println("downloaded at: " + sdf.format(resultdate) + " | " + compressedFile);
93  DumpResource.lastDumpTime = sdf.format(resultdate);
94  Thread.currentThread().sleep(DumpResource.sleepTimeInMills);
95  if (DumpResource.dumping) {
96  writeFile();
97  }
98  } catch (Exception e) {
99  System.out.println(e.toString());
100  throw new IllegalStateException(e.toString());
101  }
102  }

References TarGZ.compressWithoutFolder(), DumpResource.downloadLink, DumpResource.dumbNo, DumpResource.dumping, DumpResource.fileDir, DumpResource.filePath, DumpResource.getNumberOfStatements(), DumpResource.lastDump, DumpResource.lastDumpTime, DumpResource.listDumpFilesDeleteForMax(), DumpResource.sleepTimeInMills, DumpResource.tmpDirPath, DumpResource.tmpDirPath2, DumpResource.tmpDirString, and DumpResource.tmpDirString2.

Referenced by LSDump.run().

v1.utils.dump.LSDump.writeFile
void writeFile()
Definition: LSDump.java:28
Exception