Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8149958

Implementation/documantation of AudioInputStream.read()/skip() should be updated

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8, 9
    • client-libs
    • b114
    • generic
    • generic

    Description

      Two methods AudioInputStream.read()/skip() are quite similar but have some small inconsistency which should be fixed

      diff -r 4f90dceb5efb src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java
      --- a/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java Sun Feb 14 02:39:15 2016 +0300
      +++ b/src/java.desktop/share/classes/javax/sound/sampled/AudioInputStream.java Tue Feb 16 18:58:12 2016 +0300
      @@ -249,13 +249,14 @@
            */
           @Override
           public int read(byte[] b, int off, int len) throws IOException {
      + // make sure we don't read fractions of a frame.
      + final int reminder = len % frameSize;
      + if (reminder != 0) {
      + len -= reminder;
      + }
       
      - // make sure we don't read fractions of a frame.
      - if( (len%frameSize) != 0 ) {
      - len -= (len%frameSize);
      - if (len == 0) {
      - return 0;
      - }
      + if (len <= 0) {
      + return 0;
               }
       
               if( frameLength != AudioSystem.NOT_SPECIFIED ) {
      @@ -312,6 +313,10 @@
           /**
            * Skips over and discards a specified number of bytes from this audio input
            * stream.
      + * <p>
      + * 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,16 +326,16 @@
            */
           @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.
                   if ((n / frameSize) > (frameLength - framePos)) {

      Attachments

        Activity

          People

            serb Sergey Bylokhov
            serb Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: