当前位置: 首页>>代码示例>>Java>>正文


Java Response.getOutputStream方法代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getOutputStream方法的具体用法?Java Response.getOutputStream怎么用?Java Response.getOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.grizzly.http.server.Response的用法示例。


在下文中一共展示了Response.getOutputStream方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send404

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send404(Response response) {
    response.setStatus(HttpStatus.NOT_FOUND_404);

    response.setContentType("image/png");

    try (InputStream is = this.getClass().getResourceAsStream("/404.png");
        OutputStream os = response.getOutputStream();) {
        byte[] b = new byte[1024];
        while (is.read(b) >= 0) {
            os.write(b);
        }

    } catch (IOException e) {
        logger.error(e);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例2: send403

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send403(Response response) {
    response.setStatus(HttpStatus.FORBIDDEN_403);

    response.setContentType("image/png");

    try (InputStream is = this.getClass().getResourceAsStream("/403.png");
        OutputStream os = response.getOutputStream();) {
        byte[] b = new byte[1024];
        while (is.read(b) >= 0) {
            os.write(b);
        }

    } catch (IOException e) {
        logger.error(e);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例3: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {

    response.setContentType("application/osm");
    String uri = request.getDecodedRequestURI();
    int suffixIndex = uri.lastIndexOf('.');
    String fileType = uri.substring(suffixIndex);
    OutputStream outStream = response.getOutputStream();
    try {
        String[] coords = uri.substring(1, suffixIndex).split("[,;]");
        double minLat = Double.parseDouble(coords[0]);
        double minLon = Double.parseDouble(coords[1]);
        double maxLat = Double.parseDouble(coords[2]);
        double maxLon = Double.parseDouble(coords[3]);
        if (minLat >= maxLat || minLon >= maxLon || minLat < -90 || maxLat > 90 || minLon < -180 || maxLon > 180) {
            throw new IllegalArgumentException();
        }
        /* Respond to head requests to let the client know the server is alive and the request is valid. */
        if (request.getMethod() == Method.HEAD) {
            response.setStatus(HttpStatus.OK_200);
            return;
        }
        /* TODO filter out buildings on the server side. */
        boolean buildings = coords.length > 4 && "buildings".equalsIgnoreCase(coords[4]);

        OSMEntitySink sink = OSMEntitySink.forStream(uri, outStream);
        TileOSMSource tileSource = new TileOSMSource(osm);
        tileSource.setBoundingBox(minLat, minLon, maxLat, maxLon);
        tileSource.copyTo(sink);
        response.setStatus(HttpStatus.OK_200);
    } catch (Exception ex) {
        response.setStatus(HttpStatus.BAD_REQUEST_400);
        outStream.write("URI format: /min_lat,min_lon,max_lat,max_lon[.pbf|.vex] (all coords in decimal degrees)\n".getBytes());
        ex.printStackTrace();
    } finally {
        outStream.close();
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:39,代码来源:VanillaExtract.java

示例4: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
    
    if ( request.getMethod() == Method.POST ) {
        InputStream is = request.getInputStream();
        JSONTokener tok = new JSONTokener(new InputStreamReader(is));
        JSONObject obj = new JSONObject(tok);
        String tmpHtml = obj.getString("html");
        String tmpJava = obj.getString("java");
        
        Compile res = Compile.create(tmpHtml, tmpJava);
        List<Diagnostic<? extends JavaFileObject>> err = res.getErrors();
        if (err.isEmpty()) {
            data = res;
            response.getOutputStream().write("[]".getBytes());
            response.setStatus(HttpStatus.OK_200);
        } else {
            
            JSONArray errors = new JSONArray();
            
            for (Diagnostic<? extends JavaFileObject> d : err) {
                JSONObject e = new JSONObject();
                e.put("col", d.getColumnNumber());
                e.put("line", d.getLineNumber());
                e.put("kind", d.getKind().toString());
                e.put("msg", d.getMessage(Locale.ENGLISH));
                errors.put(e);
            }
            
            errors.write(response.getWriter());                
            response.setStatus(HttpStatus.PRECONDITION_FAILED_412);
        }
        
        return;
    }
    
    String r = request.getHttpHandlerPath();
    if (r == null || r.equals("/")) {
        r = "index.html";
    }
    if (r.equals("/result.html")) {
        response.setContentType("text/html");
        if (data != null) {
            response.getOutputBuffer().write(data.getHtml());
        }
        response.setStatus(HttpStatus.OK_200);
        return;
    }
    
    if (r.startsWith("/")) {
        r = r.substring(1);
    }
    
    if (r.endsWith(".html") || r.endsWith(".xhtml")) {
        response.setContentType("text/html");
    }
    OutputStream os = response.getOutputStream();
    try (InputStream is = Dew.class.getResourceAsStream(r) ) {
        copyStream(is, os, request.getRequestURL().toString() );
    } catch (IOException ex) {
        response.setDetailMessage(ex.getLocalizedMessage());
        response.setError();
        response.setStatus(404);
    }
}
 
开发者ID:jtulach,项目名称:dew,代码行数:66,代码来源:Dew.java


注:本文中的org.glassfish.grizzly.http.server.Response.getOutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。