@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
  public void exportData(HttpServletResponse resp, Principal prin) throws IOException {

    resp.setContentType(MediaType.APPLICATION_JSON_VALUE);

    // this writer puts things out onto the wire
    JsonWriter writer = new JsonWriter(resp.getWriter());
    writer.setIndent("  ");

    try {

      writer.beginObject();

      writer.name("exported-at");
      writer.value(dateFormat.format(new Date()));

      writer.name("exported-from");
      writer.value(config.getIssuer());

      writer.name("exported-by");
      writer.value(prin.getName());

      // delegate to the service to do the actual export
      dataService_1_3.exportData(writer);

      writer.endObject(); // end root
      writer.close();

    } catch (IOException e) {
      logger.error("Unable to export data", e);
    }
  }
예제 #2
0
  @Nullable
  public static String newDocumentText(@NotNull final IpnbFilePanel ipnbPanel) {
    final IpnbFile ipnbFile = ipnbPanel.getIpnbFile();
    if (ipnbFile == null) return null;
    for (IpnbEditablePanel panel : ipnbPanel.getIpnbPanels()) {
      if (panel.isModified()) {
        panel.updateCellSource();
      }
    }

    final IpnbFileRaw fileRaw = new IpnbFileRaw();
    fileRaw.metadata = ipnbFile.getMetadata();
    if (ipnbFile.getNbformat() == 4) {
      for (IpnbCell cell : ipnbFile.getCells()) {
        fileRaw.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat()));
      }
    } else {
      final IpnbWorksheet worksheet = new IpnbWorksheet();
      worksheet.cells.clear();
      for (IpnbCell cell : ipnbFile.getCells()) {
        worksheet.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat()));
      }
      fileRaw.worksheets = new IpnbWorksheet[] {worksheet};
    }
    final StringWriter stringWriter = new StringWriter();
    final JsonWriter writer = new JsonWriter(stringWriter);
    writer.setIndent(" ");
    gson.toJson(fileRaw, fileRaw.getClass(), writer);
    return stringWriter.toString();
  }
예제 #3
0
  private void pushWriter(ByteArrayOutputStream baos) {
    OutputStreamWriter osw = new OutputStreamWriter(baos, Charsets.UTF_8);

    JsonWriter writer = new JsonWriter(osw);
    writer.setIndent("  "); // two spaces

    WriterByteArrayOutputStream wbaos = new WriterByteArrayOutputStream(writer, baos);
    writers.push(wbaos);
  }
예제 #4
0
파일: Gson.java 프로젝트: gusfl/Tinder-repo
 private JsonWriter newJsonWriter(Writer writer) throws IOException {
   if (this.generateNonExecutableJson) {
     writer.write(JSON_NON_EXECUTABLE_PREFIX);
   }
   JsonWriter jsonWriter = new JsonWriter(writer);
   if (this.prettyPrinting) {
     jsonWriter.setIndent("  ");
   }
   jsonWriter.setSerializeNulls(this.serializeNulls);
   return jsonWriter;
 }
예제 #5
0
 @Override
 @Transactional
 public void exportEntities(ImportExportBlueprint blueprint, Writer writer) {
   try (JsonWriter jsonWriter = new JsonWriter(writer)) {
     jsonWriter.setIndent("  ");
     ExportContext exportContext =
         new ExportContext(sortBlueprintRecords(blueprint), bundleContext, allEntities);
     ExportWriter exportWriter = new ExportWriter(jsonWriter, exportContext);
     exportWriter.export();
   } catch (IOException e) {
     throw new ImportExportException("An IO error occurred during export.", e);
   }
 }
 private static void write(File file, JsonElement element) {
   try {
     Closer closer = Closer.create();
     try {
       FileOutputStream stream = closer.register(new FileOutputStream(file));
       Writer fileWriter = closer.register(new OutputStreamWriter(stream, StandardCharsets.UTF_8));
       JsonWriter jsonWriter = closer.register(new JsonWriter(fileWriter));
       jsonWriter.setIndent("    ");
       Streams.write(element, jsonWriter);
     } finally {
       closer.close();
     }
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
 public void write(Writer writer, boolean pretty) throws IOException {
   JsonWriter w = new JsonWriter(writer);
   w.setIndent(pretty ? "    " : "");
   write(w);
 }