Class BaseNJsonWriter<Record>

java.lang.Object
gov.nasa.pds.registry.common.util.json.BaseNJsonWriter<Record>
Type Parameters:
Record - A data record to write.
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
DDNJsonWriter

public abstract class BaseNJsonWriter<Record> extends Object implements Closeable
Base abstract class to write data records to a new-line-delimited JSON (NJSON) file. NJSON file has 2 lines per data record: 1 - primary key, 2 - data record. This is the file format used by Elasticsearch bulk load API.
Author:
karpenko
  • Field Details

  • Constructor Details

    • BaseNJsonWriter

      public BaseNJsonWriter(File file, String action) throws Exception
      Constructor
      Parameters:
      file - output file
      Throws:
      Exception - an exception
  • Method Details

    • writeDataRecord

      public abstract void writeDataRecord(com.google.gson.stream.JsonWriter jw, Record data) throws Exception
      Overwrite this method to write a data record.
      Parameters:
      jw - JSON writer
      data - a record
      Throws:
      Exception - an exception
    • close

      public void close() throws IOException
      Close file.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • write

      public void write(String pk, Record data) throws Exception
      Write a primary key and a data record.
      Parameters:
      pk - primary key
      data - data record
      Throws:
      Exception - an exception
    • write

      public void write(String pk, Record data, String action) throws Exception
      Write a primary key and a data record.
      Parameters:
      pk - primary key
      data - data record
      action - "index" / "create"
      Throws:
      Exception - an exception
    • newLine

      protected void newLine() throws Exception
      Throws:
      Exception
    • writePK

      protected void writePK(String id, String action) throws Exception
      Write primary key
      Parameters:
      id - primary key
      action - "index" / "create"
      Throws:
      Exception - an exception