当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.skipBytes方法代码示例

本文整理汇总了Java中java.io.RandomAccessFile.skipBytes方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.skipBytes方法的具体用法?Java RandomAccessFile.skipBytes怎么用?Java RandomAccessFile.skipBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.skipBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findCentralDirectory

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static CentralDirectory findCentralDirectory(RandomAccessFile raf) throws IOException, ZipException {
    long scanOffset = raf.length() - 22;
    if (scanOffset < 0) {
        throw new ZipException("File too short to be a zip file: " + raf.length());
    }
    long stopOffset = scanOffset - 65536;
    if (stopOffset < 0) {
        stopOffset = 0;
    }
    int endSig = Integer.reverseBytes(ENDSIG);
    do {
        raf.seek(scanOffset);
        if (raf.readInt() == endSig) {
            raf.skipBytes(2);
            raf.skipBytes(2);
            raf.skipBytes(2);
            raf.skipBytes(2);
            CentralDirectory dir = new CentralDirectory();
            dir.size = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
            dir.offset = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
            return dir;
        }
        scanOffset--;
    } while (scanOffset >= stopOffset);
    throw new ZipException("End Of Central Directory signature not found");
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:ZipUtil.java

示例2: replaceSecondPageOnly

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Usually can use this method, previously comment and setup header all fit on page 2
 * and they still do, so just replace this page. And copy further pages as is.
 *
 * @param vorbisHeaderSizes
 * @param newCommentLength
 * @param newSecondPageLength
 * @param secondPageHeader
 * @param newComment
 * @param secondPageHeaderEndPos
 * @param raf
 * @param rafTemp
 * @throws IOException
 */
private void replaceSecondPageOnly(
        OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes,
        int newCommentLength,
        int newSecondPageLength,
        OggPageHeader secondPageHeader,
        ByteBuffer newComment,
        long secondPageHeaderEndPos,
        RandomAccessFile raf,
        RandomAccessFile rafTemp) throws IOException {
    logger.fine("WriteOgg Type 1");
    ByteBuffer secondPageBuffer = startCreateBasicSecondPage(vorbisHeaderSizes, newCommentLength, newSecondPageLength, secondPageHeader, newComment);

    raf.seek(secondPageHeaderEndPos);
    //Skip comment header
    raf.skipBytes(vorbisHeaderSizes.getCommentHeaderSize());
    //Read in setup header and extra packets
    raf.getChannel().read(secondPageBuffer);
    calculateChecksumOverPage(secondPageBuffer);
    rafTemp.getChannel().write(secondPageBuffer);
    rafTemp.getChannel().transferFrom(raf.getChannel(), rafTemp.getFilePointer(), raf.length() - raf.getFilePointer());
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:36,代码来源:OggVorbisTagWriter.java

示例3: findCentralDirectory

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static CentralDirectory findCentralDirectory(RandomAccessFile raf) throws IOException,
        ZipException {
    long scanOffset = raf.length() - ENDHDR;
    if (scanOffset < 0) {
        throw new ZipException("File too short to be a zip file: " + raf.length());
    }

    long stopOffset = scanOffset - 0x10000 /* ".ZIP file comment"'s max length */;
    if (stopOffset < 0) {
        stopOffset = 0;
    }

    int endSig = Integer.reverseBytes(ENDSIG);
    while (true) {
        raf.seek(scanOffset);
        if (raf.readInt() == endSig) {
            break;
        }

        scanOffset--;
        if (scanOffset < stopOffset) {
            throw new ZipException("End Of Central Directory signature not found");
        }
    }
    // Read the End Of Central Directory. ENDHDR includes the signature
    // bytes,
    // which we've already read.

    // Pull out the information we need.
    raf.skipBytes(2); // diskNumber
    raf.skipBytes(2); // diskWithCentralDir
    raf.skipBytes(2); // numEntries
    raf.skipBytes(2); // totalNumEntries
    CentralDirectory dir = new CentralDirectory();
    dir.size = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
    dir.offset = Integer.reverseBytes(raf.readInt()) & 0xFFFFFFFFL;
    return dir;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:39,代码来源:ZipUtil.java

示例4: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {

        // throws IllegalArgumentException if not supported
        WaveFileFormat waveFileFormat = (WaveFileFormat)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 = writeWaveFile(stream, waveFileFormat, 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( waveFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {

            int dataLength=bytesWritten-waveFileFormat.getHeaderSize();
            int riffLength=dataLength + waveFileFormat.getHeaderSize() - 8;

            RandomAccessFile raf=new RandomAccessFile(out, "rw");
            // skip RIFF magic
            raf.skipBytes(4);
            raf.writeInt(big2little( riffLength ));
            // skip WAVE magic, fmt_ magic, fmt_ length, fmt_ chunk, data magic
            raf.skipBytes(4+4+4+WaveFileFormat.getFmtChunkSize(waveFileFormat.getWaveType())+4);
            raf.writeInt(big2little( dataLength ));
            // that's all
            raf.close();
        }

        return bytesWritten;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:WaveFileWriter.java

示例5: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {

        // 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;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:AuFileWriter.java

示例6: seekWithinLevel

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Seek for box with the specified id starting from the current location of filepointer,
 * <p/>
 * Note it wont find the box if it is contained with a level below the current level, nor if we are
 * at a parent atom that also contains data and we havent yet processed the data. It will work
 * if we are at the start of a child box even if it not the required box as long as the box we are
 * looking for is the same level (or the level above in some cases).
 *
 * @param raf
 * @param id
 * @return
 * @throws java.io.IOException
 */
public static Mp4BoxHeader seekWithinLevel(RandomAccessFile raf, String id) throws IOException {
    logger.finer("Started searching for:" + id + " in file at:" + raf.getChannel().position());

    Mp4BoxHeader boxHeader = new Mp4BoxHeader();
    ByteBuffer headerBuffer = ByteBuffer.allocate(HEADER_LENGTH);
    int bytesRead = raf.getChannel().read(headerBuffer);
    if (bytesRead != HEADER_LENGTH) {
        return null;
    }
    headerBuffer.rewind();
    boxHeader.update(headerBuffer);
    while (!boxHeader.getId().equals(id)) {
        logger.finer("Found:" + boxHeader.getId() + " Still searching for:" + id + " in file at:" + raf.getChannel().position());

        //Something gone wrong probably not at the start of an atom so return null;
        if (boxHeader.getLength() < Mp4BoxHeader.HEADER_LENGTH) {
            return null;
        }
        int noOfBytesSkipped = raf.skipBytes(boxHeader.getDataLength());
        logger.finer("Skipped:" + noOfBytesSkipped);
        if (noOfBytesSkipped < boxHeader.getDataLength()) {
            return null;
        }
        headerBuffer.rewind();
        bytesRead = raf.getChannel().read(headerBuffer);
        logger.finer("Header Bytes Read:" + bytesRead);
        headerBuffer.rewind();
        if (bytesRead == Mp4BoxHeader.HEADER_LENGTH) {
            boxHeader.update(headerBuffer);
        } else {
            return null;
        }
    }
    return boxHeader;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:49,代码来源:Mp4BoxHeader.java

示例7: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // throws IllegalArgumentException if not supported
    WaveFileFormat waveFileFormat = (WaveFileFormat)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 = writeWaveFile(stream, waveFileFormat, 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( waveFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {

        int dataLength=bytesWritten-waveFileFormat.getHeaderSize();
        int riffLength=dataLength + waveFileFormat.getHeaderSize() - 8;

        RandomAccessFile raf=new RandomAccessFile(out, "rw");
        // skip RIFF magic
        raf.skipBytes(4);
        raf.writeInt(big2little( riffLength ));
        // skip WAVE magic, fmt_ magic, fmt_ length, fmt_ chunk, data magic
        raf.skipBytes(4+4+4+WaveFileFormat.getFmtChunkSize(waveFileFormat.getWaveType())+4);
        raf.writeInt(big2little( dataLength ));
        // that's all
        raf.close();
    }

    return bytesWritten;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:WaveFileWriter.java

示例8: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:AuFileWriter.java

示例9: findPosition

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private long findPosition(File file, Date date) throws IOException {
	RandomAccessFile raf = new RandomAccessFile(file, "r");
	
	try {
		Date cur_date = extractDate(raf);
		if (cur_date != null) {
			int compare = date.compareTo(cur_date);
			if (compare > 0) {
				date.setTime(date.getTime() - 1);
				long min = raf.getFilePointer();
				long max = raf.length();
				Date last_date = null;
				long last_pos = 0;
				while (cur_date != null && !cur_date.equals(last_date) && !cur_date.equals(date)) {
					last_date = cur_date;
					last_pos = raf.getFilePointer();
					long cur = min + ((max - min) / 2);
					raf.seek(cur);
					cur_date = extractDate(raf);
					if (cur_date == null || date.compareTo(cur_date) < 0) {
						max = cur;
					} else {
						min = cur;
					}
				}
				date.setTime(date.getTime() + 1);
				
				if (cur_date != null && date.compareTo(cur_date) < 0) {
					raf.seek(min);
					cur_date = extractDate(raf);
				}
				
				// Fix #1788 : 'Out of range Date' exception when start date is 2011-01-25 12:32 for log file of #1787
				// can find next cur_date but last_date is a valid candidate for the end date
				if (cur_date == null && last_date != null) {
					cur_date = last_date;
					raf.seek(last_pos);
				}
				while (cur_date != null && date.compareTo(cur_date) > 0) {
					raf.skipBytes(1);
					cur_date = extractDate(raf);
				}
			}
			if (cur_date != null) {
				return raf.getFilePointer();
			}
		}
		throw new IOException("Out of range Date");
	} finally {
		raf.close();
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:53,代码来源:TemporalInputStream.java

示例10: skipRecord

import java.io.RandomAccessFile; //导入方法依赖的package包/类
protected static void skipRecord(RandomAccessFile fileHandle,
                                 int offset) throws IOException {
  fileHandle.seek(offset);
  int length = fileHandle.readInt();
  fileHandle.skipBytes(length);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:7,代码来源:LogFile.java

示例11: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void write(Tag tag, RandomAccessFile raf, RandomAccessFile rafTemp) throws CannotReadException, CannotWriteException, IOException
{
    logger.config("Starting to write file:");

    //1st Page:Identification Header
    logger.fine("Read 1st Page:identificationHeader:");
    OggPageHeader pageHeader = OggPageHeader.read(raf);
    raf.seek(pageHeader.getStartByte());

    //Write 1st page (unchanged) and place writer pointer at end of data
    rafTemp.getChannel().transferFrom(raf.getChannel(), 0, pageHeader.getPageLength() + OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageHeader.getSegmentTable().length);
    rafTemp.skipBytes(pageHeader.getPageLength() + OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageHeader.getSegmentTable().length);
    logger.fine("Written identificationHeader:");

    //2nd page:Comment and Setup if there is enough room, may also (although not normally) contain audio frames
    OggPageHeader secondPageHeader = OggPageHeader.read(raf);

    //2nd Page:Store the end of Header
    long secondPageHeaderEndPos = raf.getFilePointer();
    logger.fine("Read 2nd Page:comment and setup and possibly audio:Header finishes at file position:" + secondPageHeaderEndPos);

    //Get header sizes
    raf.seek(0);
    OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes = reader.readOggVorbisHeaderSizes(raf);

    //Convert the OggVorbisComment header to raw packet data
    ByteBuffer newComment = tc.convert(tag);

    //Compute new comment length(this may need to be spread over multiple pages)
    int newCommentLength = newComment.capacity();

    //Calculate new size of new 2nd page
    int newSecondPageDataLength = vorbisHeaderSizes.getSetupHeaderSize() + newCommentLength + vorbisHeaderSizes.getExtraPacketDataSize();
    logger.fine("Old 2nd Page no of packets: " + secondPageHeader.getPacketList().size());
    logger.fine("Old 2nd Page size: " + secondPageHeader.getPageLength());
    logger.fine("Old last packet incomplete: " + secondPageHeader.isLastPacketIncomplete());
    logger.fine("Setup Header Size: " + vorbisHeaderSizes.getSetupHeaderSize());
    logger.fine("Extra Packets: " + vorbisHeaderSizes.getExtraPacketList().size());
    logger.fine("Extra Packet Data Size: " + vorbisHeaderSizes.getExtraPacketDataSize());
    logger.fine("Old comment: " + vorbisHeaderSizes.getCommentHeaderSize());
    logger.fine("New comment: " + newCommentLength);
    logger.fine("New Page Data Size: " + newSecondPageDataLength);
    //Second Page containing new vorbis, setup and possibly some extra packets can fit on one page
    if (isCommentAndSetupHeaderFitsOnASinglePage(newCommentLength, vorbisHeaderSizes.getSetupHeaderSize(), vorbisHeaderSizes.getExtraPacketList()))
    {
        //And if comment and setup header originally fitted on both, the length of the 2nd
        //page must be less than maximum size allowed
        //AND
        //there must be two packets with last being complete because they may have
        //elected to split the setup over multiple pages instead of using up whole page - (as long
        //as the last lacing value is 255 they can do this)
        //   OR
        //There are more than the packets in which case have complete setup header and some audio packets
        //we dont care if the last audio packet is split on next page as long as we preserve it
        if ((secondPageHeader.getPageLength() < OggPageHeader.MAXIMUM_PAGE_DATA_SIZE) && (((secondPageHeader.getPacketList().size() == 2) && (!secondPageHeader.isLastPacketIncomplete())) || (secondPageHeader.getPacketList().size() > 2)))
        {
            logger.fine("Header and Setup remain on single page:");
            replaceSecondPageOnly(vorbisHeaderSizes, newCommentLength, newSecondPageDataLength, secondPageHeader, newComment, secondPageHeaderEndPos, raf, rafTemp);
        }
        //Original 2nd page spanned multiple pages so more work to do
        else
        {
            logger.fine("Header and Setup now on single page:");
            replaceSecondPageAndRenumberPageSeqs(vorbisHeaderSizes, newCommentLength, newSecondPageDataLength, secondPageHeader, newComment, raf, rafTemp);
        }
    }
    //Bit more complicated, have to create more than one new page and renumber subsequent audio
    else
    {
        logger.fine("Header and Setup with shift audio:");
        replacePagesAndRenumberPageSeqs(vorbisHeaderSizes, newCommentLength, secondPageHeader, newComment, raf, rafTemp);
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:74,代码来源:OggVorbisTagWriter.java

示例12: convertToVorbisSetupHeaderPacket

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * The Vorbis Setup Header may span multiple(2) pages, athough it doesnt normally. We pass the start of the
 * file offset of the OggPage it belongs on, it probably won't be first packet.
 *
 * @param fileOffsetOfStartingOggPage
 * @param raf
 * @return
 * @throws org.jaudiotagger.audio.exceptions.CannotReadException
 * @throws java.io.IOException
 */
public byte[] convertToVorbisSetupHeaderPacket(long fileOffsetOfStartingOggPage, RandomAccessFile raf) throws IOException, CannotReadException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    //Seek to specified offset
    raf.seek(fileOffsetOfStartingOggPage);

    //Read Page
    OggPageHeader setupPageHeader = OggPageHeader.read(raf);

    //Assume that if multiple packets first packet is VorbisComment and second packet
    //is setupheader
    if (setupPageHeader.getPacketList().size() > 1) {
        raf.skipBytes(setupPageHeader.getPacketList().get(0).getLength());
    }

    //Now should be at start of next packet, check this is the vorbis setup header
    byte[] b = new byte[VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH];
    raf.read(b);
    if (!isVorbisSetupHeader(b)) {
        throw new CannotReadException("Unable to find setup header(2), unable to write ogg file");
    }

    //Go back to start of setupheader data
    raf.seek(raf.getFilePointer() - (VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH));

    //Read data
    if (setupPageHeader.getPacketList().size() > 1) {
        b = new byte[setupPageHeader.getPacketList().get(1).getLength()];
        raf.read(b);
        baos.write(b);
    } else {
        b = new byte[setupPageHeader.getPacketList().get(0).getLength()];
        raf.read(b);
        baos.write(b);
    }

    //Return Data
    if (!setupPageHeader.isLastPacketIncomplete() || setupPageHeader.getPacketList().size() > 2) {
        logger.config("Setupheader finishes on this page");
        return baos.toByteArray();
    }

    //The Setupheader extends to the next page, so should be at end of page already
    //so carry on reading pages until we get to the end of comment
    while (true) {
        logger.config("Reading another page");
        OggPageHeader nextPageHeader = OggPageHeader.read(raf);
        b = new byte[nextPageHeader.getPacketList().get(0).getLength()];
        raf.read(b);
        baos.write(b);

        //Because there is at least one other packet this means the Setupheader Packet has finished
        //on this page so thats all we need and we can return
        if (nextPageHeader.getPacketList().size() > 1) {
            logger.config("Setupheader finishes on this page");
            return baos.toByteArray();
        }

        //There is only the Setupheader packet on page if it has completed on this page we can return
        if (!nextPageHeader.isLastPacketIncomplete()) {
            logger.config("Setupheader finish on Page because this packet is complete");
            return baos.toByteArray();
        }
    }
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:76,代码来源:OggVorbisTagReader.java

示例13: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {

        // throws IllegalArgumentException if not supported
        AiffFileFormat aiffFileFormat = (AiffFileFormat)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 = writeAiffFile(stream, aiffFileFormat, 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( aiffFileFormat.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
            int ssndBlockSize           = (aiffFileFormat.getFormat().getChannels() * aiffFileFormat.getFormat().getSampleSizeInBits());

            int aiffLength=bytesWritten;
            int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16;
            long dataSize=ssndChunkSize-16;
            int numFrames=(int) (dataSize*8/ssndBlockSize);

            RandomAccessFile raf=new RandomAccessFile(out, "rw");
            // skip FORM magic
            raf.skipBytes(4);
            raf.writeInt(aiffLength-8);
            // skip aiff2 magic, fver chunk, comm magic, comm size, channel count,
            raf.skipBytes(4+aiffFileFormat.getFverChunkSize()+4+4+2);
            // write frame count
            raf.writeInt(numFrames);
            // skip sample size, samplerate, SSND magic
            raf.skipBytes(2+10+4);
            raf.writeInt(ssndChunkSize-8);
            // that's all
            raf.close();
        }

        return bytesWritten;
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:AiffFileWriter.java

示例14: write

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // throws IllegalArgumentException if not supported
    AiffFileFormat aiffFileFormat = (AiffFileFormat)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 = writeAiffFile(stream, aiffFileFormat, 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( aiffFileFormat.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
        int channels = aiffFileFormat.getFormat().getChannels();
        int sampleSize = aiffFileFormat.getFormat().getSampleSizeInBits();
        int ssndBlockSize = channels * ((sampleSize + 7) / 8);

        int aiffLength=bytesWritten;
        int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16;
        long dataSize=ssndChunkSize-16;
        //TODO possibly incorrect round
        int numFrames = (int) (dataSize / ssndBlockSize);

        RandomAccessFile raf=new RandomAccessFile(out, "rw");
        // skip FORM magic
        raf.skipBytes(4);
        raf.writeInt(aiffLength-8);
        // skip aiff2 magic, fver chunk, comm magic, comm size, channel count,
        raf.skipBytes(4+aiffFileFormat.getFverChunkSize()+4+4+2);
        // write frame count
        raf.writeInt(numFrames);
        // skip sample size, samplerate, SSND magic
        raf.skipBytes(2+10+4);
        raf.writeInt(ssndChunkSize-8);
        // that's all
        raf.close();
    }

    return bytesWritten;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:AiffFileWriter.java

示例15: ChunkHeader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Reads an AIFF Chunk.
 */
protected boolean readChunk
(RandomAccessFile raf, long bytesRemaining)
        throws IOException {
    Chunk chunk = null;
    ChunkHeader chunkh = new ChunkHeader();
    if (!chunkh.readHeader(raf)) {
        return false;
    }
    int chunkSize = (int) chunkh.getSize();
    bytesRemaining -= chunkSize + 8;

    String id = chunkh.getID();
    if ("FVER".equals(id)) {
        chunk = new FormatVersionChunk(chunkh, raf, aiffHeader);
    } else if ("APPL".equals(id)) {
        chunk = new ApplicationChunk(chunkh, raf, aiffHeader);
        // Any number of application chunks is ok
    } else if ("COMM".equals(id)) {
        // There should be no more than one of these
        chunk = new CommonChunk(chunkh, raf, aiffHeader);
    } else if ("COMT".equals(id)) {
        chunk = new CommentsChunk(chunkh, raf, aiffHeader);
    } else if ("NAME".equals(id)) {
        chunk = new NameChunk(chunkh, raf, aiffHeader);
    } else if ("AUTH".equals(id)) {
        chunk = new AuthorChunk(chunkh, raf, aiffHeader);
    } else if ("(c) ".equals(id)) {
        chunk = new CopyrightChunk(chunkh, raf, aiffHeader);
    } else if ("ANNO".equals(id)) {
        chunk = new AnnotationChunk(chunkh, raf, aiffHeader);
    } else if ("ID3 ".equals(id)) {
        chunk = new ID3Chunk(chunkh, raf, aiffTag);
    }

    if (chunk != null) {
        if (!chunk.readChunk()) {
            return false;
        }
    } else {
        // Other chunk types are legal, just skip over them
        raf.skipBytes(chunkSize);
    }
    if ((chunkSize & 1) != 0) {
        // Must come out to an even byte boundary
        raf.skipBytes(1);
        --bytesRemaining;
    }
    return true;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:53,代码来源:AiffFileReader.java


注:本文中的java.io.RandomAccessFile.skipBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。