Reuse existing File copy function to handle audio parser tmp files

pull/167/head
luccioman 7 years ago
parent f77f8f40f9
commit 11611dbdcf

@ -24,10 +24,7 @@
package net.yacy.document.parser; package net.yacy.document.parser;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -48,11 +45,11 @@ import org.jaudiotagger.tag.Tag;
import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.document.id.MultiProtocolURL; import net.yacy.cora.document.id.MultiProtocolURL;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.document.AbstractParser; import net.yacy.document.AbstractParser;
import net.yacy.document.Document; import net.yacy.document.Document;
import net.yacy.document.Parser; import net.yacy.document.Parser;
import net.yacy.document.VocabularyScraper; import net.yacy.document.VocabularyScraper;
import net.yacy.kelondro.util.FileUtils;
/** /**
* this parser can parse id3 tags of mp3 audio files * this parser can parse id3 tags of mp3 audio files
@ -235,7 +232,6 @@ public class audioTagParser extends AbstractParser implements Parser {
filename = filename.isEmpty() ? location.toTokens() : MultiProtocolURL.unescape(filename); filename = filename.isEmpty() ? location.toTokens() : MultiProtocolURL.unescape(filename);
Document[] docs; Document[] docs;
BufferedOutputStream fout = null;
File tempFile = null; File tempFile = null;
AudioFile f; AudioFile f;
@ -245,11 +241,7 @@ public class audioTagParser extends AbstractParser implements Parser {
} else { } else {
// create a temporary file, as jaudiotagger requires a file rather than an input stream // create a temporary file, as jaudiotagger requires a file rather than an input stream
tempFile = File.createTempFile(filename, "." + fileext); tempFile = File.createTempFile(filename, "." + fileext);
fout = new BufferedOutputStream(new FileOutputStream(tempFile)); FileUtils.copy(source, tempFile);
int c;
while ((c = source.read()) != -1) {
fout.write(c);
}
f = AudioFileIO.read(tempFile); f = AudioFileIO.read(tempFile);
} }
@ -344,15 +336,13 @@ public class audioTagParser extends AbstractParser implements Parser {
new Date() new Date()
)}; )};
} finally { } finally {
try { if (tempFile != null) {
if (fout != null)
fout.close();
} catch (final IOException e) {
// TODO Auto-generated catch block
ConcurrentLog.logException(e);
}
if (tempFile != null)
tempFile.delete(); tempFile.delete();
/*
* If temp file deletion failed it should not be an issue as the operation is
* delayed to JVM exit (see YaCy custome temp directory deletion in yacy class)
*/
}
} }
return docs; return docs;
} }

Loading…
Cancel
Save