AuFileWriter.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:openjdk-jdk10 作者:
@Override
public int write(AudioInputStream stream, Type fileType, File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // throws IllegalArgumentException if not supported
    AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);

    // first write the file without worrying about length fields
    FileOutputStream fos = new FileOutputStream( out );     // throws IOException
    BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
    int bytesWritten = writeAuFile(stream, auFileFormat, bos );
    bos.close();

    // now, if length fields were not specified, calculate them,
    // open as a random access file, write the appropriate fields,
    // close again....
    if( auFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {

        // $$kk: 10.22.99: jan: please either implement this or throw an exception!
        // $$fb: 2001-07-13: done. Fixes Bug 4479981
        RandomAccessFile raf=new RandomAccessFile(out, "rw");
        if (raf.length()<=0x7FFFFFFFl) {
            // skip AU magic and data offset field
            raf.skipBytes(8);
            raf.writeInt(bytesWritten-AuFileFormat.AU_HEADERSIZE);
            // that's all
        }
        raf.close();
    }

    return bytesWritten;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号