public void writeError ( int httpcode , String msg , String cxt , String other ) throws IOException { dmr8 = null ; ErrorResponse response = new ErrorResponse ( httpcode , msg , cxt , other ) ; String errorbody = response . buildXML ( ) ; // Convert the error body into utf8 then to byte[] byte [ ] errbody8 = DapUtil . extract ( DapUtil . UTF8 . encode ( errorbody ) ) ; if ( mode == RequestMode . DMR ) { sendDXR ( errbody8 ) ; } else { //mode == DATA // clear any partial chunk chunk . clear ( ) ; // create an error header int flags = DapUtil . CHUNK_ERROR | DapUtil . CHUNK_END ; chunkheader ( errbody8 . length , flags , header ) ; output . write ( DapUtil . extract ( header ) ) ; output . write ( errbody8 ) ; output . flush ( ) ; } state = State . ERROR ; }
Write an error chunk . If mode == DMR then replaces the dmr else reset the current chunk thus losing any partial write .