labelingsystem-server  Version 0.1.0.0
Dump Class Reference

Static Public Member Functions

static String writeFile (String repo)
 

Member Function Documentation

◆ writeFile()

static String writeFile ( String  repo)
static
15  {
16  try {
17  String tmpDirString = "tmpDir";
18  String tmpDirPath = ConfigProperties.getPropertyParam("dump_server") + tmpDirString + "/";
19  String fileDir = ConfigProperties.getPropertyParam("dump_server");
20  // create tmp folder
21  File tmpDir1 = new File(tmpDirPath.substring(0, tmpDirPath.length() - 1));
22  if (!tmpDir1.exists()) {
23  if (tmpDir1.mkdir()) {
24  } else {
25  System.out.println("Failed to create directory!");
26  }
27  }
28  // download dump
29  URL link = new URL(ConfigProperties.getPropertyParam("ts_server") + "/repositories/" + repo + "/statements?Accept=text/plain");
30  InputStream in = new BufferedInputStream(link.openStream());
31  ByteArrayOutputStream out = new ByteArrayOutputStream();
32  byte[] buf = new byte[1024];
33  int n = 0;
34  while (-1 != (n = in.read(buf))) {
35  out.write(buf, 0, n);
36  }
37  out.close();
38  in.close();
39  byte[] response2 = out.toByteArray();
40  long currentTime = System.currentTimeMillis();
41  String fileName = tmpDirPath + String.valueOf(currentTime) + ".ttl";
42  FileOutputStream fos = new FileOutputStream(fileName);
43  fos.write(response2);
44  fos.close();
45  // compress folder
46  String compressedFile = fileDir + String.valueOf(currentTime) + "_" + repo + ".tar.gz";
47  TarGZ.compressWithoutFolder(tmpDirPath, compressedFile, tmpDirString);
48  // delete tmp folder
49  FileUtils.deleteDirectory(new File(tmpDirPath));
50  // return
51  return String.valueOf(currentTime) + "_" + repo + ".tar.gz";
52  } catch (Exception e) {
53  System.out.println(e.toString());
54  throw new IllegalStateException(e.toString());
55  }
56  }

References TarGZ.compressWithoutFolder(), and ConfigProperties.getPropertyParam().

Referenced by DumpResource.getDump().

Exception