Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  
      ngs-gtr  Mapping for GTR XSDs.
      Copyright (c) 2014 National Marrow Donor Program (NMDP)
  
      This library is free software; you can redistribute it and/or modify it
      under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation; either version 3 of the License, or (at
      your option) any later version.
 
     This library is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     License for more details.
 
     You should have received a copy of the GNU Lesser General Public License
     along with this library;  if not, write to the Free Software Foundation,
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 
     > http://www.gnu.org/licenses/lgpl.html
 
 */
 package org.nmdp.ngs.gtr;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.net.URL;
 
 import java.io.File;
 import java.io.Writer;
 
 
 
 
 
Writer for GTR public data xml.
 
 public final class GtrWriter {

    
Private no-arg constructor.
 
     private GtrWriter() {
         // empty
     }


    
Write the specified GTR public data to the specified writer.

Parameters:
data GTR public data to write, must not be null
writer writer to write to, must not be null
Throws:
java.io.IOException if an I/O error occurs
 
     public static void write(final GTRPublicData datafinal Writer writerthrows IOException {
         checkNotNull(data);
         checkNotNull(writer);
 
         try {
             // todo:  may want to cache some of this for performance reasons
             JAXBContext context = JAXBContext.newInstance(GTRPublicData.class);
             Marshaller marshaller = context.createMarshaller();
             SchemaFactory schemaFactory = SchemaFactory.newInstance(.);
             URL schemaURL = GtrReader.class.getResource("/org/nmdp/ngs/gtr/xsd/GTRPublicData.xsd");
             Schema schema = schemaFactory.newSchema(schemaURL);
             marshaller.setSchema(schema);
             marshaller.setProperty(.true);
             marshaller.marshal(datawriter);
         }
         catch (JAXBException | SAXException e) {
             throw new IOException("could not marshal GTRPublicData"e);
         }
     }

    
Write the specified GTR public data to the specified file.

Parameters:
data GTR public data to write, must not be null
file file to write to, must not be null
Throws:
java.io.IOException if an I/O error occurs
 
     public static void write(final GTRPublicData datafinal File filethrows IOException {
         checkNotNull(data);
         checkNotNull(file);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            write(datawriter);
        }
    }

    
Write the specified GTR public data to the specified output stream.

Parameters:
data GTR public data to write, must not be null
outputStream output stream to write to, must not be null
Throws:
java.io.IOException if an I/O error occurs
    public static void write(final GTRPublicData datafinal OutputStream outputStreamthrows IOException {
        checkNotNull(data);
        checkNotNull(outputStream);
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) {
            write(datawriter);
        }
    }
New to GrepCode? Check out our FAQ X