Package htsjdk.samtools

# Class SAMTextWriter

java.lang.Object
htsjdk.samtools.SAMFileWriterImpl
htsjdk.samtools.SAMTextWriter

All Implemented Interfaces:
  `SAMFileWriter`, `Closeable`, `AutoCloseable`

public class SAMTextWriter extends SAMFileWriterImpl
Writer for text-format SAM files.

## Constructor Summary

Constructors
Constructor
Description
`SAMTextWriter(File file)`
Constructs a SAMTextWriter that writes to a File.
`SAMTextWriter(File file, SamFlagField samFlagFieldOutput)`
Constructs a SAMTextWriter that writes to a File.
`SAMTextWriter(OutputStream stream)`
Constructs a SAMTextWriter that writes to an OutputStream.
`SAMTextWriter(OutputStream stream, SamFlagField samFlagFieldOutput)`
Constructs a SAMTextWriter that writes to an OutputStream.
`SAMTextWriter(Writer out)`
Constructs a SAMTextWriter that outputs to a Writer.
`SAMTextWriter(Writer out, SamFlagField samFlagFieldOutput)`
Constructs a SAMTextWriter that outputs to a Writer.

## Method Summary

Modifier and Type
Method
Description
`void`
`finish()`
Do any required flushing here.
`String`
`getFilename()`
For producing error messages.
`Writer`
`getWriter()`
Returns the Writer used by this instance.
`void`
`writeAlignment(SAMRecord alignment)`
Write the record.
`protected void`
`writeHeader(SAMFileHeader header)`
Write the header to disk.
`void`
`writeHeader(String textHeader)`
Write the header text.

### Methods inherited from class htsjdk.samtools.SAMFileWriterImpl

`addAlignment, close, getDefaultMaxRecordsInRam, getFileHeader, getMaxRecordsInRam, getSortOrder, getTempDirectory, setDefaultMaxRecordsInRam, setHeader, setMaxRecordsInRam, setProgressLogger, setSortOrder, setSortOrderChecking, setTempDirectory`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SAMTextWriter

public SAMTextWriter(Writer out)
Constructs a SAMTextWriter that outputs to a Writer.

Parameters:
  `out` - Writer.

### SAMTextWriter

public SAMTextWriter(File file)
Constructs a SAMTextWriter that writes to a File.

Parameters:
  `file` - Where to write the output.

### SAMTextWriter

public SAMTextWriter(OutputStream stream)
Constructs a SAMTextWriter that writes to an OutputStream. The OutputStream is wrapped in an AsciiWriter, which can be retrieved with getWriter().

Parameters:
  `stream` - Need not be buffered because this class provides buffering.

### SAMTextWriter

public SAMTextWriter(Writer out, SamFlagField samFlagFieldOutput)
Constructs a SAMTextWriter that outputs to a Writer.

Parameters:
  `out` - Writer.

### SAMTextWriter

public SAMTextWriter(File file, SamFlagField samFlagFieldOutput)
Constructs a SAMTextWriter that writes to a File.

Parameters:
  `file` - Where to write the output.

### SAMTextWriter

public SAMTextWriter(OutputStream stream, SamFlagField samFlagFieldOutput)
Constructs a SAMTextWriter that writes to an OutputStream. The OutputStream is wrapped in an AsciiWriter, which can be retrieved with getWriter().

Parameters:
  `stream` - Need not be buffered because this class provides buffering.

## Method Details

### getWriter

public Writer getWriter()
Returns the Writer used by this instance. Useful for flushing the output.

### writeAlignment

public void writeAlignment(SAMRecord alignment)
Write the record.

Specified by:
  `writeAlignment` in class `SAMFileWriterImpl`
Parameters:
  `alignment` - SAMRecord.

### writeHeader

public void writeHeader(String textHeader)
Write the header text. This method can also be used to write an arbitrary String, not necessarily the header.

Specified by:
  `writeHeader` in class `SAMFileWriterImpl`
Parameters:
  `textHeader` - String containing the text to write.

### writeHeader

protected void writeHeader(SAMFileHeader header)
Description copied from class: `SAMFileWriterImpl`
Write the header to disk. Header object is available via getHeader().

IMPORTANT: this method will be abstract once `SAMFileWriterImpl.writeHeader(String)` is removed.

Note: default implementation uses `SAMTextHeaderCodec.encode(java.io.Writer, htsjdk.samtools.SAMFileHeader)` and calls `SAMFileWriterImpl.writeHeader(String)`.

Overrides:
  `writeHeader` in class `SAMFileWriterImpl`
Parameters:
  `header` - object to write.

### finish

public void finish()
Do any required flushing here.

Specified by:
  `finish` in class `SAMFileWriterImpl`

### getFilename

public String getFilename()
For producing error messages.

Specified by:
  `getFilename` in class `SAMFileWriterImpl`
Returns:
  Output filename, or null if there isn't one.