Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.totsp.crossword;

import com.totsp.crossword.io.IO;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -134,7 +136,11 @@ private void initializeDownload() {
InputStream is = response.body().byteStream();
File puzFile = new File(crosswordsFolder, filename);
FileOutputStream fos = new FileOutputStream(puzFile);
copyStream(is, fos);
try {
copyStream(is, fos);
} finally {
IO.closeQuietly(is);
}
fos.close();

Intent i = new Intent(Intent.ACTION_EDIT, Uri.fromFile(puzFile), this, PlayActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import android.net.Uri;

import com.totsp.crossword.io.IO;
import com.totsp.crossword.io.JPZIO;
import com.totsp.crossword.puz.PuzzleMeta;
import com.totsp.crossword.versions.AndroidVersionUtils;
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/totsp/crossword/net/NYTDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -133,8 +134,12 @@ protected File download(Date date, String urlSuffix) {
.apply();
File f = new File(downloadDirectory, this.createFileName(date));
FileOutputStream fos = new FileOutputStream(f);
IO.copyStream(
response.body().byteStream(), fos);
InputStream is = response.body().byteStream();
try {
IO.copyStream(is, fos);
} finally {
IO.closeQuietly(is);
}
fos.close();

IO.copyStream(
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/totsp/crossword/versions/DefaultUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import com.totsp.crossword.io.IO;
import com.totsp.crossword.puz.PuzzleMeta;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -44,10 +43,12 @@ public boolean downloadFile(URL url, File destination,
Response response = httpclient.newCall(requestBuilder.build()).execute();

FileOutputStream fos = new FileOutputStream(destination);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

IO.copyStream(response.body().byteStream(), baos);
IO.copyStream(new ByteArrayInputStream(baos.toByteArray()), fos);
InputStream is = response.body().byteStream();
try {
IO.copyStream(is, fos);
} finally {
IO.closeQuietly(is);
}
fos.close();
return true;

Expand Down
10 changes: 10 additions & 0 deletions puzlib/src/main/java/com/totsp/crossword/io/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,14 @@ public static int copyStream(InputStream sourceStream, OutputStream destinationS
return totalBytes;
}

public static void closeQuietly(InputStream is) {
if (is == null) {
return;
}
try {
is.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public Puzzle download(Date d){
} catch (IOException ex) {
Logger.getLogger(AbstractDownloader.class.getName()).log(Level.SEVERE, null, ex);
return null;
} finally {
IO.closeQuietly(is);
}
}
}
Expand Down