From a7a856ca67628e555cb684ff217ab3cb4cfb6d35 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Mon, 28 Mar 2016 18:02:10 +0300 Subject: [PATCH] 8149958: Implementation/documantation of AudioInputStream.read()/skip() should be updated Reviewed-by: amenkov, prr --- .../javax/sound/sampled/AudioInputStream.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java b/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java index 716b9902331..242a3157d99 100644 --- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java +++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -249,10 +249,10 @@ public class AudioInputStream extends InputStream { */ @Override public int read(byte[] b, int off, int len) throws IOException { - // make sure we don't read fractions of a frame. - if( (len%frameSize) != 0 ) { - len -= (len%frameSize); + final int reminder = len % frameSize; + if (reminder != 0) { + len -= reminder; if (len == 0) { return 0; } @@ -312,6 +312,10 @@ public class AudioInputStream extends InputStream { /** * Skips over and discards a specified number of bytes from this audio input * stream. + *

+ * This method will always skip an integral number of frames. If {@code n} + * does not specify an integral number of frames, a maximum of + * {@code n - (n % frameSize)} bytes will be skipped. * * @param n the requested number of bytes to be skipped * @return the actual number of bytes skipped @@ -321,15 +325,14 @@ public class AudioInputStream extends InputStream { */ @Override public long skip(long n) throws IOException { - if (n <= 0) { - return 0; - } - // make sure not to skip fractional frames final long reminder = n % frameSize; if (reminder != 0) { n -= reminder; } + if (n <= 0) { + return 0; + } if (frameLength != AudioSystem.NOT_SPECIFIED) { // don't skip more than our set length in frames.