< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/RIFFReader.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 139             return -1;
 140         }
 141         if (len > avail) {
 142             int rlen = stream.read(b, offset, (int)avail);
 143             if (rlen != -1)
 144                 filepointer += rlen;
 145             avail = 0;
 146             return rlen;
 147         } else {
 148             int ret = stream.read(b, offset, len);
 149             if (ret == -1) {
 150                 avail = 0;
 151                 return -1;
 152             }
 153             avail -= ret;
 154             filepointer += ret;
 155             return ret;
 156         }
 157     }
 158 
 159     public void readFully(byte b[]) throws IOException {
 160         readFully(b, 0, b.length);
 161     }
 162 
 163     public void readFully(byte b[], int off, int len) throws IOException {
 164         if (len < 0)
 165             throw new IndexOutOfBoundsException();
 166         while (len > 0) {
 167             int s = read(b, off, len);
 168             if (s < 0)
 169                 throw new EOFException();
 170             if (s == 0)
 171                 Thread.yield();
 172             off += s;
 173             len -= s;
 174         }
 175     }
 176 
 177     @Override
 178     public long skip(final long n) throws IOException {
 179         if (n <= 0 || avail == 0) {
 180             return 0;
 181         }
 182         // will not skip more than
 183         long remaining = Math.min(n, avail);


   1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 139             return -1;
 140         }
 141         if (len > avail) {
 142             int rlen = stream.read(b, offset, (int)avail);
 143             if (rlen != -1)
 144                 filepointer += rlen;
 145             avail = 0;
 146             return rlen;
 147         } else {
 148             int ret = stream.read(b, offset, len);
 149             if (ret == -1) {
 150                 avail = 0;
 151                 return -1;
 152             }
 153             avail -= ret;
 154             filepointer += ret;
 155             return ret;
 156         }
 157     }
 158 
 159     public void readFully(byte[] b) throws IOException {
 160         readFully(b, 0, b.length);
 161     }
 162 
 163     public void readFully(byte[] b, int off, int len) throws IOException {
 164         if (len < 0)
 165             throw new IndexOutOfBoundsException();
 166         while (len > 0) {
 167             int s = read(b, off, len);
 168             if (s < 0)
 169                 throw new EOFException();
 170             if (s == 0)
 171                 Thread.yield();
 172             off += s;
 173             len -= s;
 174         }
 175     }
 176 
 177     @Override
 178     public long skip(final long n) throws IOException {
 179         if (n <= 0 || avail == 0) {
 180             return 0;
 181         }
 182         // will not skip more than
 183         long remaining = Math.min(n, avail);


< prev index next >