Skip to content

Commit

Permalink
less important refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hexian000 committed Jun 4, 2018
1 parent 971dc92 commit 36c406b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

The app do only transfer files between Android

For example: You can share files over WLAN or WLAN direct or hotspot between Android phones using **Mass Transfer**.
For example: You can share files over Wi-Fi or Wi-Fi direct or hotspot between Android phones using **Mass Transfer**.

Goal: "reasonable fast" & "as simple as possible"

Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/com/Ostermiller/util/CircularByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ public class CircularByteBuffer {
* The default max capacity for a circular byte buffer.
*/
private final static int DEFAULT_CAPACITY = 2 * 1024 * 1024;

/**
* The InputStream that can empty this buffer.
*/
private final InputStream in = new CircularByteBufferInputStream();
/**
* The OutputStream that can fill this buffer.
*/
private final OutputStream out = new CircularByteBufferOutputStream();
/**
* The circular buffer.
* <p>
* The actual capacity of the buffer is one less than the actual length
* of the buffer so that an empty and a full buffer can be
* distinguished. An empty buffer will have the markPostion and the
* distinguished. An empty buffer will have the markPosition and the
* writePosition equal to each other. A full buffer will have
* the writePosition one less than the markPostion.
* the writePosition one less than the markPosition.
* <p>
* There are three important indexes into the buffer:
* The readPosition, the writePosition, and the markPosition.
Expand Down Expand Up @@ -94,18 +101,10 @@ public class CircularByteBuffer {
* to support mark() and reset() on the InputStream.
*/
private volatile int markSize = 0;
/**
* The InputStream that can empty this buffer.
*/
private InputStream in = new CircularByteBufferInputStream();
/**
* true if the close() method has been called on the InputStream
*/
private boolean inputStreamClosed = false;
/**
* The OutputStream that can fill this buffer.
*/
private OutputStream out = new CircularByteBufferOutputStream();
/**
* true if the close() method has been called on the OutputStream
*/
Expand Down Expand Up @@ -321,7 +320,7 @@ private void ensureMark() {
/**
* Class for reading from a circular byte buffer.
*/
protected class CircularByteBufferInputStream extends InputStream {
class CircularByteBufferInputStream extends InputStream {

/**
* Returns the number of bytes that can be read (or skipped over) from this
Expand Down Expand Up @@ -558,7 +557,7 @@ public long skip(long n) throws IOException, IllegalArgumentException {
* until there is some space available or throw an IOException
* based on the CircularByteBuffer's preference.
*/
protected class CircularByteBufferOutputStream extends OutputStream {
class CircularByteBufferOutputStream extends OutputStream {

/**
* Close the stream, flushing it first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void run() {
Log.d(LOG_TAG, "ReceiveService begins to listen");
listener.setSoTimeout(1000); // prevent thread leak
listener.setPerformancePreferences(0, 0, 1);
listener.setReceiveBufferSize(512 * 1024);
listener.setReceiveBufferSize(TcpBufferSize);
while (!isInterrupted()) {
try {
socket = listener.accept();
Expand All @@ -146,7 +146,7 @@ public void run() {
Log.d(LOG_TAG, "ReceiveService accepted connection");
socket.setPerformancePreferences(0, 0, 1);
socket.setTrafficClass(IPTOS_THROUGHPUT);
socket.setReceiveBufferSize(512 * 1024);
socket.setReceiveBufferSize(TcpBufferSize);
socket.setSoTimeout(30000);
streamCopy(socket);
} catch (SocketTimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void run() {
socket = new Socket();
socket.setPerformancePreferences(0, 0, 1);
socket.setTrafficClass(IPTOS_THROUGHPUT);
socket.setSendBufferSize(512 * 1024);
socket.setSendBufferSize(TcpBufferSize);
socket.setSoTimeout(30000);
socket.setSoLinger(true, 30);
socket.setTcpNoDelay(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static me.hexian000.masstransfer.MassTransfer.CHANNEL_TRANSFER_STATE;

public abstract class TransferService extends Service {
final static int TcpBufferSize = 512 * 1024;
final Handler handler = new Handler();
DocumentFile root = null;
Notification.Builder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Thread unsafe
public class AverageRateCounter extends RateCounter {
private long[] values;
private final long[] values;
private long sum;
private int pos;

Expand Down

0 comments on commit 36c406b

Please sign in to comment.