public Response downloadApk() { String absolutePath = mPrefs.getString(Config.SP_APK_DIR, ""); try { FileInputStream f = new FileInputStream(absolutePath); File file = new File(absolutePath); Response res = newChunkedResponse(Response.Status.OK, "application/vnd.android.package-archive", f);//new Response(Response.Status.OK, "application/vnd.android.package-archive", f, (int) file.length()); String appName = mPrefs.getString(Config.SP_PACKAGE, "") + ".apk"; res.addHeader("Content-Disposition", "attachment;filename=" + appName); return res; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
public Response downloadAll() { String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); try { int time = (int) Calendar.getInstance().getTimeInMillis(); String zipName = mPrefs.getString(Config.SP_PACKAGE, "") + "-" + String.valueOf(time) + ".zip"; String fullZipPath = sdcardPath + "/" + Config.P_ROOT + "/" + zipName; String fullPath = mPrefs.getString(Config.SP_DATA_DIR, "") + Config.P_ROOT; if (mPrefs.getBoolean(Config.SP_HAS_W_PERMISSION, false)) { fullPath = sdcardPath + "/" + Config.P_ROOT+ "/"+ mPrefs.getString(Config.SP_PACKAGE,""); } FileUtil.zipFolder(fullPath, fullZipPath); FileInputStream f = new FileInputStream(fullZipPath); File file = new File(fullZipPath); Response res = newChunkedResponse(Response.Status.OK, "application/zip", f);//new Response(Response.Status.OK, "application/zip", f, (int) file.length()); res.addHeader("Content-Disposition", "attachment;filename=" + file.getName()); return res; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
public Response downloadFileRoot(String path) { String filename = path.substring(path.lastIndexOf("/") + 1); String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); if(new File(sdcardPath + Config.P_ROOT ).exists() && new File("/storage/emulated/legacy").exists()){ sdcardPath = "/storage/emulated/legacy"; } String absolutePath = sdcardPath + Config.P_ROOT + "/" + filename; Util.copyFileRoot(path, absolutePath); try { FileInputStream f = new FileInputStream(absolutePath); File file = new File(absolutePath); Response res = newChunkedResponse(Response.Status.OK, "application/octet-stream", f);//new Response(Response.Status.OK, "application/octet-stream", f, (int) file.length()); res.addHeader("Content-Disposition", "attachment;filename=" + filename); file.delete(); return res; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
public void decorate(NanoHTTPD.Response response) { for (Header header : headers) { response.addHeader(header.getKey(), header.getValue()); } } }
/** * レスポンスを作成する. * * @param status ステータス * @param mimeType MIMEタイプ * @param message メッセージ (String) * @return レスポンス */ private Response createResponse(final Response.Status status, final String mimeType, final String message) { Response res = new Response(status, mimeType, message); res.addHeader("Accept-Ranges", "bytes"); return res; }
private void addHeaders(Response response, IMap header) { // TODO add first class support for cache control on the Rascal side. For // now we prevent any form of client-side caching with this.. hopefully. response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.addHeader("Pragma", "no-cache"); response.addHeader("Expires", "0"); for (IValue key : header) { response.addHeader(((IString) key).getValue(), ((IString) header.get(key)).getValue()); } }
private static void addHeaders(Response response, IMap header) { // TODO add first class support for cache control on the Rascal side. For // now we prevent any form of client-side caching with this.. hopefully. response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.addHeader("Pragma", "no-cache"); response.addHeader("Expires", "0"); for (IValue key : header) { response.addHeader(((IString) key).getValue(), ((IString) header.get(key)).getValue()); } }
private Response newFixedFileResponse(File file, String mime) throws FileNotFoundException { Response res; res = newFixedLengthResponse(Response.Status.OK, mime, new FileInputStream(file), (int) file.length()); res.addHeader("Accept-Ranges", "bytes"); return res; }
public static Response newFixedLengthResponse(IStatus status, String mimeType, String message) { Response response = NanoHTTPD.newFixedLengthResponse(status, mimeType, message); response.addHeader("Accept-Ranges", "bytes"); return response; }
private void addHeaders(Response response, IMap header) { // TODO add first class support for cache control on the Rascal side. For // now we prevent any form of client-side caching with this.. hopefully. response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.addHeader("Pragma", "no-cache"); response.addHeader("Expires", "0"); for (IValue key : header) { response.addHeader(((IString) key).getValue(), ((IString) header.get(key)).getValue()); } }
/** * Internally used by the webserver to add all queued cookies into the Response's HTTP Headers. * * @param response The Response object to which headers the queued cookies will be added. */ public void unloadQueue(Response response) { for (Cookie cookie : queue) { response.addHeader("Set-Cookie", cookie.getHTTPHeader()); } } }
protected Response addCORSHeaders(Map<String, String> queryHeaders, Response resp, String cors) { resp.addHeader("Access-Control-Allow-Origin", cors); resp.addHeader("Access-Control-Allow-Headers", calculateAllowHeaders(queryHeaders)); resp.addHeader("Access-Control-Allow-Credentials", "true"); resp.addHeader("Access-Control-Allow-Methods", ALLOWED_METHODS); resp.addHeader("Access-Control-Max-Age", "" + MAX_AGE); return resp; }
public NanoHTTPD.Response getResponse() { response.addHeader("Access-Control-Allow-Origin", "*"); return response; } }
/** * Internally used by the webserver to add all queued cookies into the Response's HTTP Headers. * * @param response The Response object to which headers the queued cookies will be added. */ public void unloadQueue(Response response) { for (Cookie cookie : queue) { response.addHeader("Set-Cookie", cookie.getHTTPHeader()); } } }
private Response createResponse(Response.Status status, String mimeType, InputStream message) { Response res = new Response(status, mimeType, message); res.addHeader("Accept-Ranges", "bytes"); return res; }
public WebSocket(NanoHTTPD.IHTTPSession handshakeRequest) { this.handshakeRequest = handshakeRequest; this.in = handshakeRequest.getInputStream(); this.handshakeResponse.addHeader(NanoWSD.HEADER_UPGRADE, NanoWSD.HEADER_UPGRADE_VALUE); this.handshakeResponse.addHeader(NanoWSD.HEADER_CONNECTION, NanoWSD.HEADER_CONNECTION_VALUE); }
public Response takeScreenshot() { int time = (int) Calendar.getInstance().getTimeInMillis(); String fileName = String.valueOf(time) + ".png"; Util.takeScreenshot(fileName); String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); String absolutePath = sdcardPath + Config.P_ROOT + "/"+ fileName; try { FileInputStream f = new FileInputStream(absolutePath); File file = new File(absolutePath); Response res = newChunkedResponse(Response.Status.OK, "image/png", f);//new Response(Response.Status.OK, "image/png", f, (int) file.length()); res.addHeader("Content-Disposition", "attachment;filename=" + fileName); return res; } catch (FileNotFoundException e) { //response with some alert e.printStackTrace(); } return null; }