Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication7;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.InetSocketAddress;
- import com.sun.net.httpserver.HttpExchange;
- import com.sun.net.httpserver.HttpHandler;
- import com.sun.net.httpserver.HttpServer;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- /*
- * a simple static http server
- */
- public class SimpleHttpServer {
- public static void main(String[] args) throws Exception {
- HttpServer server = HttpServer.create(new InetSocketAddress(80), 0);
- server.createContext("/crysis.iso", new MyHandler());
- server.setExecutor(null); // creates a default executor
- server.start();
- }
- static class MyHandler implements HttpHandler {
- public void handle(HttpExchange t) throws IOException {
- System.out.println("Connection");
- //File file = new File("D:\\OSs\\GSP1RMCPRXFREO_EN_DVD.iso");C:\Program Files (x86)\SCAR Divi
- File file = new File("D:\\Games\\Crysis 1.iso");
- InputStream in = new FileInputStream(file);
- long len = file.length();
- t.sendResponseHeaders(200, len);
- OutputStream os = t.getResponseBody();
- byte[] buf = new byte[1024 * 1024 * 8];
- int read;
- long start = System.nanoTime() / 1000000L, time;
- while ((read = in.read(buf)) != -1) {
- os.write(buf, 0, read);
- time = (System.nanoTime() / 1000000L) - start;
- long bytesms = read / time;
- long bytess = bytesms * 1000;
- double mbs = bytess / 1024L / 1024D;
- start = System.nanoTime() / 1000000L;
- System.out.println(mbs * 8 + "mb/s");
- }
- os.close();
- in.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement