add static version of saveStream()

This commit is contained in:
benfry
2007-11-24 18:45:09 +00:00
parent b6b4fa1066
commit 1775a31125
2 changed files with 17 additions and 8 deletions
+12 -8
View File
@@ -4650,8 +4650,8 @@ in */
* This is basically saveBytes(blah, loadBytes()), but done
* in a less confusing manner.
*/
public void saveStream(String filename, String stream) {
saveStream(saveFile(filename), stream);
public void saveStream(String targetFilename, String sourceLocation) {
saveStream(saveFile(targetFilename), sourceLocation);
}
@@ -4661,14 +4661,18 @@ in */
* Note that unlike other api methods, this will not automatically
* uncompress gzip files.
*/
public void saveStream(File file, String stream) {
public void saveStream(File targetFile, String sourceLocation) {
saveStream(targetFile, openStreamRaw(sourceLocation));
}
static public void saveStream(File targetFile, InputStream sourceStream) {
File tempFile = null;
try {
File parentDir = file.getParentFile();
tempFile = File.createTempFile(file.getName(), null, parentDir);
File parentDir = targetFile.getParentFile();
tempFile = File.createTempFile(targetFile.getName(), null, parentDir);
InputStream is = openStream(stream);
BufferedInputStream bis = new BufferedInputStream(is, 16384);
BufferedInputStream bis = new BufferedInputStream(sourceStream, 16384);
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
@@ -4682,7 +4686,7 @@ in */
bos.close();
bos = null;
if (!tempFile.renameTo(file)) {
if (!tempFile.renameTo(targetFile)) {
System.err.println("Could not rename temporary file " +
tempFile.getAbsolutePath());
}
+5
View File
@@ -1,6 +1,11 @@
0136 core
X add static version of saveStream() (uses a File and InputStream object)
_ can loadBytes() be improved by querying file size first?
_ loadBytes() is used for images.. ouch
_ can bug 77 be fixed with a finalizer?
_ remove gzip-related hint()
reference/online