@Override public void handle(HttpExchange t) throws IOException { String fileId = t.getRequestURI().getPath().replaceFirst("/header/", ""); System.out.println("fileId: " + fileId); InputStream is = new FileInputStream("C:\\Users\\vadim\\Downloads\\15496_1#45.cram"); CramHeader cramHeader = CramIO.readCramHeader(is); t.getResponseHeaders().add(HttpHeaders.CONTENT_TYPE, "SAM_HEADER"); t.getResponseHeaders() .add( "CRAM_VERSION", String.format("%d.%d", cramHeader.getMajorVersion(), cramHeader.getMinorVersion())); t.sendResponseHeaders(200, 0); ByteArrayOutputStream headerBodyOS = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(headerBodyOS); new SAMTextHeaderCodec().encode(w, cramHeader.getSamFileHeader()); try { w.close(); } catch (IOException e) { throw new RuntimeException(e); } OutputStream os = t.getResponseBody(); os.write(headerBodyOS.toByteArray()); os.close(); }
public BaiIndexer(InputStream is, File output) throws IOException { this.is = new CountingInputStream(is); CramHeader cramHeader = CramIO.readCramHeader(this.is); samFileHeader = cramHeader.getSamFileHeader(); indexer = new CRAMIndexer(output, samFileHeader); }