Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improve audioparser
  • Loading branch information
tballison committed May 29, 2018
1 parent dae1d5b commit 41bc34c
Showing 1 changed file with 16 additions and 0 deletions.
Expand Up @@ -32,7 +32,9 @@
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.apache.commons.io.IOUtils;
import org.apache.tika.exception.TikaException;
import org.apache.tika.io.ProxyInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.XMPDM;
import org.apache.tika.mime.MediaType;
Expand Down Expand Up @@ -66,6 +68,7 @@ public void parse(
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
stream = new SkipFullyInputStream(stream);
try {
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(stream);
Type type = fileFormat.getType();
Expand Down Expand Up @@ -137,4 +140,17 @@ private void addMetadata(Metadata metadata, Map<String, Object> properties) {
}
}

private static class SkipFullyInputStream extends ProxyInputStream {

public SkipFullyInputStream(InputStream proxy) {
super(proxy);
}

@Override
public long skip(long ln) throws IOException {
IOUtils.skipFully(in, ln);
return ln;
}
}

}

0 comments on commit 41bc34c

Please sign in to comment.