diff --git a/source/net/yacy/document/parser/audioTagParser.java b/source/net/yacy/document/parser/audioTagParser.java index 7abd80917..7b401cae1 100644 --- a/source/net/yacy/document/parser/audioTagParser.java +++ b/source/net/yacy/document/parser/audioTagParser.java @@ -226,22 +226,29 @@ public class audioTagParser extends AbstractParser implements Parser { 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 class audioTagParser extends AbstractParser implements Parser { } } - docs = new Document[]{new Document( + final Document doc = new Document( location, mime, charset, @@ -310,9 +317,9 @@ public class audioTagParser extends AbstractParser implements Parser { 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 class audioTagParser extends AbstractParser implements Parser { } } } + + @Override + public boolean isParseWithLimitsSupported() { + return true; + } /** * Process a tag field : add its value to the descriptions and to text. All diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java index 9f6df876f..711d0c71a 100644 --- a/source/net/yacy/kelondro/util/FileUtils.java +++ b/source/net/yacy/kelondro/util/FileUtils.java @@ -237,6 +237,7 @@ public final class FileUtils { * @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) @@ -244,7 +245,7 @@ public final class FileUtils { * @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(); @@ -252,7 +253,7 @@ public final class FileUtils { FileOutputStream fos = null; try { fos = new FileOutputStream(dest); - copy(source, fos, count); + return copy(source, fos, count); } finally { if ( fos != null ) { try {