/** Writes results to the given TableWriter */ public void writeTable(TableWriter tableWriter, QuerierStatus statusToUpdate) throws IOException { if (tableWriter instanceof VoTableWriter) { Piper.bufferedPipe(new InputStreamReader(in), ((VoTableWriter) tableWriter).getOut()); } else { throw new UnsupportedOperationException("Can only write to votables"); } }
/** read stream contents into a string */ public static String getStreamContents(InputStream is) throws IOException { assertNotNull(is); StringWriter sw = new StringWriter(); Piper.bufferedPipe(new InputStreamReader(is), sw); return sw.toString(); } /** handler passed to schema-validation parses - logs all errors, throws assertion failed if errors seen by end */
/** * Extracts the XML template file resources for use in constructing * conesearch queries. */ public static String getConeTemplate(String filename) throws QueryException { // Find the template as a resource of this class. if ((filename == null) || (filename.trim().equals(""))) { throw new QueryException("No name was specified for the cone-search template"); } InputStream templateIn = ConeConverter.class.getResourceAsStream(filename); // Now we have the query, let's get it as a string. try { StringWriter sw = new StringWriter(); Piper.bufferedPipe(new InputStreamReader(templateIn), sw); return sw.toString(); } catch (IOException e) { throw new QueryException("Couldn't load cone-search template", e); } }
/** Constructs a Query from a stream containing ADQL/xml. */ public Query(InputStream adqlStream, ReturnSpec returnSpec) throws QueryException { if (returnSpec == null) { throw new QueryException("ReturnSpec may not be null"); } StringWriter sw = new StringWriter(); try { Piper.bufferedPipe(new InputStreamReader(adqlStream), sw); } catch (Exception e) { throw new QueryException("Couldn't get ADQL query: "+e, e); } String adqlString = sw.toString(); setSelectDocument(adqlString); this.results = returnSpec; }
/** Constructs a Query from a stream containing ADQL/xml. */ public Query(InputStream adqlStream) throws QueryException { StringWriter sw = new StringWriter(); try { Piper.bufferedPipe(new InputStreamReader(adqlStream), sw); } catch (Exception e) { throw new QueryException("Couldn't get ADQL query: "+e, e); } String adqlString = sw.toString(); setSelectDocument(adqlString); this.results = new ReturnTable(new WriterTarget(new StringWriter())); }
out.flush(); FileReader logReader = new FileReader(palDebugFilename); Piper.bufferedPipe(logReader, out); out.flush();
/** * Handles an HTTP GET. * * @param request The HTTP request. * @param response The HTTP response. * @throws IOException If the response cannot be written out. */ @Override public void performGet(HttpServletRequest request, HttpServletResponse response) throws IOException, WebResourceNotFoundException, TapException { Job job = getJob(request); ResultFile result = new ResultFile(job.getId()); response.setContentType(job.getFormat()); response.setCharacterEncoding("UTF-8"); Writer out = response.getWriter(); if (job.getFormat().contains("xml")) { out.write("<?xml version='1.0' encoding='UTF-8'?>\n"); } Reader in = new FileReader(result); Piper.bufferedPipe(in, out); in.close(); out.close(); }
/** This is a helper method for plugins; it is meant to be called * from the askQuery method. It transforms the results and sends them * as required, updating the querier status appropriately. */ public void send(ReturnSpec returns, Principal user) throws IOException { //we have no idea what form the original image is in, so let's ignore all //requests for formatting and just pipe it straight from the url to the target if (returns instanceof ReturnImage) { if (returns.getTarget() instanceof HttpResponseTarget) { //in fact, if it's an http response, forward it to the URL ((HttpResponseTarget) returns.getTarget()).getResponse().sendRedirect(imageUrl.toString()); } else { InputStream in = imageUrl.openStream(); returns.getTarget().setMimeType("image"); OutputStream out = returns.getTarget().openOutputStream(); Piper.bufferedPipe(in, out); } } else { throw new UnsupportedOperationException("Unknown return type "+returns.getClass().getName()+", specify Image"); } }
Piper.bufferedPipe(is, os); is.close(); os.close();
Piper.bufferedPipe(is, os); is.close(); os.close();