예제 #1
0
  // <editor-fold defaultstate="collapsed" desc="import">
  @POST
  @Path("/import/zip")
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Response importZip(
      @FormDataParam("file") FormDataContentDisposition fileDisposition,
      @FormDataParam("file") InputStream file) {
    String storeDirPath = Init.getStoredQueriesPath();
    File storeDir = storeDirPath == null ? null : new File(storeDirPath);
    if (storeDir == null) return Response.status(Response.Status.NOT_FOUND).build();

    final StringBuilder res = new StringBuilder();
    if (fileDisposition != null) {
      logInfo("import {0}", fileDisposition.getFileName());
      try {
        unzip(
            storeDir,
            file,
            new Reciver<String>() {
              @Override
              public void recive(String logtext) {
                res.append(logtext.trim());
                res.append("\n");
              }
            });
      } catch (IOException ex) {
        Logger.getLogger(SqlQueriesRest.class.getName()).log(Level.SEVERE, null, ex);
        return Response.serverError().build();
      }
    }
    return Response.ok("succ\n" + res.toString()).build();
  }
예제 #2
0
  @GET
  @Path("/export/zip")
  public Response exportZip() {
    String storeDirPath = Init.getStoredQueriesPath();
    File storeDir = storeDirPath == null ? null : new File(storeDirPath);
    if (storeDir != null && storeDir.exists()) {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

      try {
        zip(byteStream, storeDir, false, "/");
      } catch (IOException ex) {
        Logger.getLogger(SqlQueriesRest.class.getName()).log(Level.SEVERE, null, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
      }

      return Response.ok()
          .type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
          .header("Content-Disposition", "attachment; filename=\"storedQueries.zip\"")
          .entity(byteStream.toByteArray())
          .build();
    } else {
      return Response.status(Response.Status.NOT_FOUND).build();
    }

    //        return Response.ok("", MediaType.TEXT_PLAIN_TYPE).build();
  }
예제 #3
0
 public File getStoreDir() {
   String p = Init.getStoredQueriesPath();
   if (p != null) return new File(p);
   return null;
 }