Skip to content

Instantly share code, notes, and snippets.

@keiono
Created December 13, 2013 20:58
Show Gist options
  • Save keiono/7951230 to your computer and use it in GitHub Desktop.
Save keiono/7951230 to your computer and use it in GitHub Desktop.
public class KeggscapeFileFilter extends BasicCyFileFilter {
private static final Logger logger = LoggerFactory.getLogger(KeggscapeFileFilter.class);
private static final String KEGG_TAG = "www.kegg.jp/kegg";
public KeggscapeFileFilter(Set<String> extensions, Set<String> contentTypes, String description,
DataCategory category, StreamUtil streamUtil) {
super(extensions, contentTypes, description, category, streamUtil);
}
public KeggscapeFileFilter(String[] extensions, String[] contentTypes, String description, DataCategory category,
StreamUtil streamUtil) {
super(extensions, contentTypes, description, category, streamUtil);
}
@Override
public boolean accepts(final InputStream stream, final DataCategory category) {
final String header = getHeader(stream, 5);
logger.debug("File header: " + header);
if (header.contains(KEGG_TAG)) {
return true;
} else {
return false;
}
}
@Override
public boolean accepts(final URI uri, final DataCategory category) {
try {
return accepts(uri.toURL().openStream(), category);
} catch (IOException e) {
logger.error("Error while opening stream: " + uri, e);
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment