< prev index next >

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

Print this page




1131 
1132                     int bytesRemaining = arraysize;
1133                     int thisRead = 0;
1134                     while (bytesRemaining > 0 && thisRead >= 0) {
1135                         thisRead = stream.read(streamData, bytesRead, bytesRemaining);
1136                         if (thisRead > 0) {
1137                             bytesRead += thisRead;
1138                             bytesRemaining -= thisRead;
1139                         }
1140                         else if (thisRead == 0) {
1141                             Thread.yield();
1142                         }
1143                     }
1144                 } else {
1145                     // read data from the stream until we reach the end of the stream
1146                     // we use a slightly modified version of ByteArrayOutputStream
1147                     // to get direct access to the byte array (we don't want a new array
1148                     // to be allocated)
1149                     int MAX_READ_LIMIT = 16384;
1150                     DirectBAOS dbaos  = new DirectBAOS();
1151                     byte tmp[] = new byte[MAX_READ_LIMIT];
1152                     int thisRead = 0;
1153                     while (thisRead >= 0) {
1154                         thisRead = stream.read(tmp, 0, tmp.length);
1155                         if (thisRead > 0) {
1156                             dbaos.write(tmp, 0, thisRead);
1157                             bytesRead += thisRead;
1158                         }
1159                         else if (thisRead == 0) {
1160                             Thread.yield();
1161                         }
1162                     } // while
1163                     streamData = dbaos.getInternalBuffer();
1164                 }
1165                 lengthInFrames = bytesRead / stream.getFormat().getFrameSize();
1166 
1167                 if (Printer.debug) Printer.debug("Read to end of stream. lengthInFrames: " + lengthInFrames);
1168 
1169                 // now try to open the device
1170                 open(stream.getFormat(), streamData, lengthInFrames);
1171 




1131 
1132                     int bytesRemaining = arraysize;
1133                     int thisRead = 0;
1134                     while (bytesRemaining > 0 && thisRead >= 0) {
1135                         thisRead = stream.read(streamData, bytesRead, bytesRemaining);
1136                         if (thisRead > 0) {
1137                             bytesRead += thisRead;
1138                             bytesRemaining -= thisRead;
1139                         }
1140                         else if (thisRead == 0) {
1141                             Thread.yield();
1142                         }
1143                     }
1144                 } else {
1145                     // read data from the stream until we reach the end of the stream
1146                     // we use a slightly modified version of ByteArrayOutputStream
1147                     // to get direct access to the byte array (we don't want a new array
1148                     // to be allocated)
1149                     int MAX_READ_LIMIT = 16384;
1150                     DirectBAOS dbaos  = new DirectBAOS();
1151                     byte[] tmp = new byte[MAX_READ_LIMIT];
1152                     int thisRead = 0;
1153                     while (thisRead >= 0) {
1154                         thisRead = stream.read(tmp, 0, tmp.length);
1155                         if (thisRead > 0) {
1156                             dbaos.write(tmp, 0, thisRead);
1157                             bytesRead += thisRead;
1158                         }
1159                         else if (thisRead == 0) {
1160                             Thread.yield();
1161                         }
1162                     } // while
1163                     streamData = dbaos.getInternalBuffer();
1164                 }
1165                 lengthInFrames = bytesRead / stream.getFormat().getFrameSize();
1166 
1167                 if (Printer.debug) Printer.debug("Read to end of stream. lengthInFrames: " + lengthInFrames);
1168 
1169                 // now try to open the device
1170                 open(stream.getFormat(), streamData, lengthInFrames);
1171 


< prev index next >