1 package com.kodexa.client.store; 2 3 import com.kodexa.client.Document; 4 import com.kodexa.client.KodexaException; 5 import lombok.extern.slf4j.Slf4j; 6 import org.apache.commons.io.FileUtils; 7 8 import java.io.IOException; 9 import java.nio.charset.Charset; 10 11 @Slf4j 12 public class JsonDocumentStore extends AbstractFileSystemDocumentStore { 13 14 @Override 15 protected String getExtension() { 16 return "json"; 17 } 18 19 public JsonDocumentStore(String path) { 20 super(path, false); 21 } 22 23 public JsonDocumentStore(String path, boolean forceInitialize) { 24 super(path, forceInitialize); 25 } 26 27 @Override 28 public Document getDocument(int position) { 29 try { 30 return Document.fromJson(FileUtils.readFileToString(getFile(index.get(position)), Charset.defaultCharset())); 31 } 32 catch (IOException e) { 33 throw new KodexaException("Unable to read the document at index " + position, e); 34 } 35 } 36 }