org.pharmgkb.parser.vcf.VcfFormatException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vcf-parser Show documentation
Show all versions of vcf-parser Show documentation
A strict streaming parser for VCF 4.1/4.2.
The newest version!
package org.pharmgkb.parser.vcf;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
/**
* This exception indicates a VCF format error was found while parsing the VCF file.
*
* @author Mark Woon
*/
public class VcfFormatException extends RuntimeException {
private int m_lineNumber;
private String m_section;
private final String m_baseMessage;
public VcfFormatException(String msg) {
Preconditions.checkNotNull(msg);
m_baseMessage = msg;
}
public VcfFormatException(String msg, int lineNumber) {
Preconditions.checkNotNull(msg);
m_baseMessage = msg;
m_lineNumber = lineNumber;
}
public VcfFormatException(String msg, Throwable ex) {
super(ex);
m_baseMessage = StringUtils.stripToNull(msg);
}
public VcfFormatException(int lineNumber, String section, Throwable ex) {
super(ex);
m_lineNumber = lineNumber;
m_section = section;
m_baseMessage = StringUtils.stripToNull(ex.getMessage());
}
public void addMetadata(int lineNumber, String section) {
m_lineNumber = lineNumber;
m_section = section;
}
@Override
public String getMessage() {
if (m_section == null) {
return m_baseMessage;
}
StringBuilder builder = new StringBuilder()
.append("[Line #")
.append(m_lineNumber)
.append("] Error parsing ")
.append(m_section);
if (m_baseMessage != null) {
builder.append(": ")
.append(m_baseMessage);
}
return builder.toString();
}
public int getLineNumber() {
return m_lineNumber;
}
@Override
public String toString() {
return getMessage();
}
}