Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Immueggpain authored and Immueggpain committed Dec 28, 2019
1 parent 358c734 commit 39b0c38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.immueggpain</groupId>
<artifactId>simple-streaming</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
version = Launcher.VERSTR, subcommands = { HelpCommand.class, StreamServer.class, Serve.class })
public class Launcher implements Callable<Void> {

public static final String VERSTR = "0.0.2";
public static final String VERSTR = "0.0.3";
public static final int LOCAL_PORT = 2233;
public static final int LOCAL_OVPN_PORT = 1194;

Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/github/immueggpain/simplestreaming/Serve.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.immueggpain.simplestreaming;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Callable;

import org.apache.commons.io.FileUtils;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

Expand Down Expand Up @@ -37,6 +37,7 @@ private void accept_thread(int listen_port) {

while (true) {
Socket socket = serverSocket.accept();
System.out.println("new client");
Thread sendThread = Util.execAsync("send_thread", () -> send_thread(socket));
sendThread.join();
}
Expand All @@ -48,13 +49,31 @@ private void accept_thread(int listen_port) {
private void send_thread(Socket socket) {
try {
OutputStream os = socket.getOutputStream();
byte[] buf = new byte[1024 * 8];

RandomAccessFile file = new RandomAccessFile(filepath, "r");
long length = file.length();
file.seek(length);

long ct = copyLarge(file, os, buf);

long ct = FileUtils.copyFile(new File(filepath), os);
System.out.println("close socket " + ct);
file.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}

private static long copyLarge(final RandomAccessFile input, final OutputStream output, final byte[] buffer)
throws IOException {
long count = 0;
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}

}

0 comments on commit 39b0c38

Please sign in to comment.