Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofrancis committed Jul 22, 2018
1 parent 31b98c3 commit d466c72
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 84 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Big thanks to @duncanokeyo on Github for continuously pointing out issues and im
- General error reporting improvements.
- FetchFileServer improvements
- FileResource class updates
- Removed FetchFileResourceDownloadTask class
- General bug fixes and improvements


Expand Down
85 changes: 1 addition & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,7 @@ public class TestActivity extends AppCompatActivity {
}
```

Download a file from a FetchFileServer using the Fetch. Add the FetchFileServerDownloader
dependency to you app's build.gradle file.
```java
implementation "com.tonyodev.fetch2downloaders:fetch2downloaders:2.2.0-RC1"
```

Then create an instance of Fetch and enqueue the download.
Downloading a file from a FetchFileServer using the Fetch is easy.

```java
public class TestActivity extends AppCompatActivity {
Expand Down Expand Up @@ -380,83 +374,6 @@ public class TestActivity extends AppCompatActivity {
};
}
```
A FetchFileResourceDownloadTask can also be used to download files from the FetchFileServer.
Be sure to add the fetch2downloaders module to your dependencies.

```java
public class TestActivity extends AppCompatActivity {

FetchFileResourceDownloadTask<File> task;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
task = new FetchFileResourceDownloadTask<File>() {
@NotNull
@Override
public FileResourceRequest getRequest() {
FileResourceRequest fileResourceRequest = new FileResourceRequest();
fileResourceRequest.setHostAddress("127.0.0.1");
fileResourceRequest.setPort(6886);
fileResourceRequest.setResourceIdentifier("testfile.txt");
fileResourceRequest.addHeader("Authorization", "5adWEDG36FGTTBX23B");
return fileResourceRequest;
}

@Override
public File doWork(@NotNull InputStream inputStream, long contentLength, @NotNull String md5CheckSum) {
File file = new File("/downloads/sample.txt");
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
byte[] buffer = new byte[1024];
int read;
int bytesRead = 0;
while ((read = bufferedInputStream.read(buffer, 0, 1024)) != -1 && !isCancelled()) { //isCancelled() checks if the task was cancelled.
bufferedOutputStream.write(buffer, 0, read);
bytesRead += read;
setProgress(calculateProgress(bytesRead, contentLength));
}
bufferedInputStream.close();
bufferedOutputStream.flush();
bufferedOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}

@Override
protected void onProgress(int progress) {
Log.d("TestActivity", "Progress: " + progress);

}

@Override
protected void onError(int httpStatusCode, @org.jetbrains.annotations.Nullable Throwable throwable) {
Log.d("TestActivity", "Error: " + httpStatusCode);
}

@Override
protected void onComplete(File result) {
Log.d("TestActivity", "Complete");
}
};
}

@Override
protected void onResume() {
super.onResume();
task.execute();
}

@Override
protected void onPause() {
super.onPause();
task.cancel();

}
```

Fetch1 Migration
----------------
Expand Down

0 comments on commit d466c72

Please sign in to comment.