package com.pengyifan.pubtator.io;

import com.google.common.base.Joiner;
import com.pengyifan.pubtator.PubTatorDocument;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.List;

public class PubTatorIO {

  public static List<PubTatorDocument> readBioCFormat(Reader reader)
      throws XMLStreamException, IOException {
    return new BioCLoader().load(reader);
  }

  public static List<PubTatorDocument> readPubTatorFormat(Reader reader)
      throws IOException {
    try (PubTatorLoader2 loader2 = new PubTatorLoader2(reader)) {
      return loader2.read();
    }
  }

  public static String toPubTatorString(List<PubTatorDocument> documentList) {
    return Joiner.on("\n\n").join(documentList);
  }

  public static void write(Writer writer, List<PubTatorDocument> documentList)
      throws IOException {
    writer.write(Joiner.on("\n\n").join(documentList));
    writer.flush();
  }
}

@@ -556,13 +556,8 @@
     
-try (
 PubT
@@ -609,46 +609,201 @@
 der)
-) %7B%0A      return loader2.read();%0A    %7D
+;%0A    List%3CPubTatorDocument%3E documents = loader2.read();%0A    loader2.close();%0A%0A    if (loader2.hasErrors()) %7B%0A      throw new IOException(loader2.getErrorMessage());%0A    %7D%0A    return documents;
 %0A  %7D

throw errors