Permalink
Browse files

Enabled partial parsing of audio resources.

  • Loading branch information...
luccioman committed Mar 1, 2018
1 parent fda0189 commit bcbd0ae1a4ea4550089b82d7ae47b93a8524e787
Showing with 23 additions and 10 deletions.
  1. +20 −8 source/net/yacy/document/parser/audioTagParser.java
  2. +3 −2 source/net/yacy/kelondro/util/FileUtils.java
@@ -226,22 +226,29 @@ public audioTagParser() {
final int timezoneOffset,
final InputStream source)
throws Parser.Failure, InterruptedException {
return parseWithLimits(location, mimeType, charset, scraper, timezoneOffset, source, Integer.MAX_VALUE, Long.MAX_VALUE);
}
@Override
public Document[] parseWithLimits(final DigestURL location, final String mimeType, final String charset, final VocabularyScraper scraper,
final int timezoneOffset, final InputStream source, final int maxLinks, final long maxBytes)
throws UnsupportedOperationException, Failure, InterruptedException {
String filename = location.getFileName();
final String fileext = MultiProtocolURL.getFileExtension(filename);
filename = filename.isEmpty() ? location.toTokens() : MultiProtocolURL.unescape(filename);
Document[] docs;
File tempFile = null;
AudioFile f;
try {
try {
boolean partiallyParsed = false;
if (location.isFile()) {
f = AudioFileIO.read(location.getFSFile());
} else {
// create a temporary file, as jaudiotagger requires a file rather than an input stream
tempFile = File.createTempFile(filename, "." + fileext);
FileUtils.copy(source, tempFile);
long bytesCopied = FileUtils.copy(source, tempFile, maxBytes);
partiallyParsed = bytesCopied == maxBytes && source.read() != -1;
f = AudioFileIO.read(tempFile);
}
@@ -292,7 +299,7 @@ public audioTagParser() {
}
}
docs = new Document[]{new Document(
final Document doc = new Document(
location,
mime,
charset,
@@ -310,9 +317,9 @@ public audioTagParser() {
null,
null,
false,
new Date())
};
return docs;
new Date());
doc.setPartiallyParsed(partiallyParsed);
return new Document[]{doc};
} catch (final Exception e) {
throw new Parser.Failure("Unexpected error while parsing audio file. " + e.getMessage(), location);
} finally {
@@ -325,6 +332,11 @@ public audioTagParser() {
}
}
}
@Override
public boolean isParseWithLimitsSupported() {
return true;
}
/**
* Process a tag field : add its value to the descriptions and to text. All
@@ -237,22 +237,23 @@ public static void copy(final InputStream source, final File dest) throws IOExce
* @param source InputStream instance
* @param dest File instance
* @param count the amount of bytes to copy (-1 for all, else must be greater than zero)
* @return the number of bytes actually copied (may be lower than count)
* @throws IOException when a read/write error occurred
* @throws NullPointerException when a parameter is null
* @see #copy(InputStream source, OutputStream dest)
* @see #copyRange(File source, OutputStream dest, int start)
* @see #copy(File source, OutputStream dest)
* @see #copy(File source, File dest)
*/
public static void copy(final InputStream source, final File dest, final long count) throws IOException {
public static long copy(final InputStream source, final File dest, final long count) throws IOException {
final String path = dest.getParent();
if ( path != null && path.length() > 0 ) {
new File(path).mkdirs();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(dest);
copy(source, fos, count);
return copy(source, fos, count);
} finally {
if ( fos != null ) {
try {

0 comments on commit bcbd0ae

Please sign in to comment.