第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

內(nèi)置網(wǎng)頁提供大文件下載內(nèi)存溢出

項(xiàng)目需求,PC通過IP地址訪問靜態(tài)網(wǎng)頁,網(wǎng)頁提供文件下載,文件過大,直接oom,求老師指導(dǎo)

public?class?ClienDownloadService?extends?Service?{
????private?ExecutorService?threadPool;
????private?ServerSocket?serverSocket;
????private?InetSocketAddress?address;
????private?boolean?isEnable;

????public?IBinder?onBind(Intent?intent)?{
????????return?null;
????}

????public?void?onCreate()?{
????????super.onCreate();
????????initPlatfrom();
????????startAsync();
????}

????public?void?initPlatfrom()?{
????????threadPool?=?Executors.newCachedThreadPool();
????}

????private?void?startAsync()?{
????????isEnable?=?true;
????????new?Thread(new?Runnable()?{

????????????public?void?run()?{
????????????????try?{
????????????????????address?=?new?InetSocketAddress(8098);
????????????????????serverSocket?=?new?ServerSocket();
????????????????????serverSocket.bind(address);
????????????????????while?(isEnable)?{
????????????????????????final?Socket?socket?=?serverSocket.accept();
????????????????????????threadPool.execute(new?Runnable()?{
????????????????????????????public?void?run()?{
????????????????????????????????try?{
????????????????????????????????????buileRemoteSocket(socket);
????????????????????????????????}?catch?(Exception?e)?{
????????????????????????????????????e.printStackTrace();
????????????????????????????????}
????????????????????????????}
????????????????????????});
????????????????????}
????????????????}?catch?(Exception?e)?{
????????????????????e.printStackTrace();
????????????????}
????????????}
????????}).start();
????}

????private?void?buileRemoteSocket(Socket?socket)?throws?Exception?{
????????InputStream?in?=?socket.getInputStream();
????????BufferedReader?reader?=?new?BufferedReader(new?InputStreamReader(in));
????????String?line?=?"";
????????while?((line?=?reader.readLine())?!=?null)?{
????????????if?(line.startsWith("GET"))?{
????????????????String?uri?=?line.split("?")[1];
????????????????response(socket,?uri);
????????????}
????????}
????}

????public?void?response(Socket?socket,?String?assetsPath)?throws?Exception?{
????????assetsPath?=?assetsPath.substring(1);
????????if?(assetsPath.equals(""))?{
????????????assetsPath?=?"index.html";
????????}
????????InputStream?in?=?getAssets().open(assetsPath);
????????ByteArrayOutputStream?bos?=?new?ByteArrayOutputStream();
????????byte[]?buffer?=?new?byte[8192];
????????int?len?=?0;
????????while?((len?=?in.read(buffer))?!=?-1)?{
????????????bos.write(buffer,?0,?len);
????????}
????????byte[]?raw?=?bos.toByteArray();

????????in.close();

????????OutputStream?nos?=?socket.getOutputStream();
????????PrintStream?printer?=?new?PrintStream(nos);
????????printer.println("HTTP/1.1?200?OK");
????????printer.println("Content-length:"?+?raw.length);
????????if?(assetsPath.endsWith(".html"))?{
????????????printer.println("Content-Type:text/html");
????????}?else?if?(assetsPath.endsWith(".js"))?{
????????????printer.println("Content-Type:text/js");
????????}?else?if?(assetsPath.endsWith(".css"))?{
????????????printer.println("Content-Type:text/css");
????????}?else?if?(assetsPath.endsWith(".jpg"))?{
????????????printer.println("Content-Type:text/jpg");
????????}?else?if?(assetsPath.endsWith(".png"))?{
????????????printer.println("Content-Type:text/png");
????????}
????????printer.println();
????????printer.write(raw);
????????printer.flush();
????????printer.close();
????}

????public?void?onDestroy()?{
????????super.onDestroy();
????????stopAsync();
????}

????public?void?stopAsync()?{
????????isEnable?=?false;
????????try?{
????????????serverSocket.close();
????????}?catch?(IOException?e)?{
????????????e.printStackTrace();
????????}
????}

}


正在回答

1 回答

解決了么

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
手機(jī)服務(wù)器微架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)
  • 參與學(xué)習(xí)       25900    人
  • 解答問題       35    個(gè)

帶你打造一個(gè)輕量級(jí)服務(wù)器微架構(gòu),積累項(xiàng)目經(jīng)驗(yàn),擺平面試官

進(jìn)入課程

內(nèi)置網(wǎng)頁提供大文件下載內(nèi)存溢出

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)