// 边读边写,直到读取size个字符------备份 private boolean readAndWrite(InputStream is, FileOutputStream os, FileOutputStream osb) { byte[] buffer_baidu_ogg = new byte[1000]; byte[] buffer_baidu_frame = new byte[1200]; // 第一块 try { int count = 1268; byte[] buffer = new byte[count]; int readCount = 0; // 已经成功读取的字节的个数 while (readCount < count) { readCount += is.read(buffer, readCount, count - readCount); } System.arraycopy(buffer, 268, buffer_baidu_ogg, 0, 1000); // 去掉文件头 System.arraycopy( processAry(buffer_baidu_ogg, 20, 4), 0, buffer_baidu_frame, 0, 24 * 50); // 帧数据改成24字节 os.write(buffer, 0, 1268); osb.write(buffer_baidu_frame, 0, 24 * 50); System.out.println("读取第一部分n=" + readCount); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // 把语音数据分块 OggPart oggPart = processOgg(size); int loopTimes = oggPart.getLoopTimes(); int restDataLength = oggPart.getRestDataLength(); // 第二块 for (int i = 0; i < loopTimes; i++) { try { int count = 1077; byte[] buffer = new byte[count]; int readCount = 0; // 已经成功读取的字节的个数 while (readCount < count) { readCount += is.read(buffer, readCount, count - readCount); } System.arraycopy(buffer, 77, buffer_baidu_ogg, 0, 1000); // 去掉ogg头 System.arraycopy( processAry(buffer_baidu_ogg, 20, 4), 0, buffer_baidu_frame, 0, 24 * 50); // 帧数据改成24字节 os.write(buffer, 0, 1077); osb.write(buffer_baidu_frame, 0, 24 * 50); System.out.println("读取第二部分n=" + readCount); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // 第三块 try { int count = 27 + restDataLength + 20 * restDataLength; byte[] buffer = new byte[count]; int readCount = 0; // 已经成功读取的字节的个数 while (readCount < count) { readCount += is.read(buffer, readCount, count - readCount); } System.arraycopy( buffer, 27 + restDataLength, buffer_baidu_ogg, 0, 20 * restDataLength); // 去掉ogg头 System.arraycopy( processAry(buffer_baidu_ogg, 20, 4), 0, buffer_baidu_frame, 0, 24 * 20 * restDataLength); // 帧数据改成24字节 os.write(buffer, 0, restDataLength * 20); osb.write(buffer_baidu_frame, 0, restDataLength * 24); System.out.println("读取第三部分n=" + readCount); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return true; }