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


Java CannotReadException类代码示例

本文整理汇总了Java中org.jaudiotagger.audio.exceptions.CannotReadException的典型用法代码示例。如果您正苦于以下问题:Java CannotReadException类的具体用法?Java CannotReadException怎么用?Java CannotReadException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getAudioHeader

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Creates a generic audio header instance with provided data from header.
 *
 * @param header ASF header which contains the information.
 * @return generic audio header representation.
 * @throws CannotReadException If header does not contain mandatory information. (Audio
 *                             stream chunk and file header chunk)
 */
private GenericAudioHeader getAudioHeader(final AsfHeader header) throws CannotReadException
{
    final GenericAudioHeader info = new GenericAudioHeader();
    if (header.getFileHeader() == null)
    {
        throw new CannotReadException("Invalid ASF/WMA file. File header object not available.");
    }
    if (header.getAudioStreamChunk() == null)
    {
        throw new CannotReadException("Invalid ASF/WMA file. No audio stream contained.");
    }
    info.setBitRate(header.getAudioStreamChunk().getKbps());
    info.setChannelNumber((int) header.getAudioStreamChunk().getChannelCount());
    info.setEncodingType("ASF (audio): " + header.getAudioStreamChunk().getCodecDescription());
    info.setLossless(header.getAudioStreamChunk().getCompressionFormat() == AudioStreamChunk.WMA_LOSSLESS);
    info.setPreciseLength(header.getFileHeader().getPreciseDuration());
    info.setSamplingRate((int) header.getAudioStreamChunk().getSamplingRate());
    info.setVariableBitRate(determineVariableBitrate(header));
    info.setBitsPerSample(header.getAudioStreamChunk().getBitsPerSample());
    return info;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:30,代码来源:AsfFileReader.java

示例2: read

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Read editable Metadata
 *
 * @param file
 * @return
 * @throws CannotReadException
 * @throws IOException
 */
public AiffTag read(File file) throws CannotReadException, IOException {
    FileChannel fc = new FileOutputStream(file.getAbsolutePath(), false).getChannel();
    AiffAudioHeader aiffAudioHeader = new AiffAudioHeader();
    AiffTag aiffTag = new AiffTag();

    final AiffFileHeader fileHeader = new AiffFileHeader();
    fileHeader.readHeader(fc, aiffAudioHeader, file.toString());
    while (fc.position() < fc.size()) {
        if (!readChunk(fc, aiffTag, file.toString())) {
            logger.severe(file + " UnableToReadProcessChunk");
            break;
        }
    }

    if (aiffTag.getID3Tag() == null) {
        aiffTag.setID3Tag(AiffTag.createDefaultID3Tag());
    }
    return aiffTag;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:28,代码来源:AiffTagReader.java

示例3: getTag

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
@Override
protected Tag getTag(RandomAccessFile raf) throws CannotReadException, IOException {
    final RealChunk cont = findContChunk(raf);
    final DataInputStream dis = cont.getDataInputStream();
    final String title = Utils.readString(dis, Utils.readUint16(dis));
    final String author = Utils.readString(dis, Utils.readUint16(dis));
    final String copyright = Utils.readString(dis, Utils.readUint16(dis));
    final String comment = Utils.readString(dis, Utils.readUint16(dis));
    final RealTag rv = new RealTag();
    // NOTE: frequently these fields are off-by-one, thus the crazy
    // logic below...
    try {
        rv.addField(FieldKey.TITLE, (title.length() == 0 ? author : title));
        rv.addField(FieldKey.ARTIST, title.length() == 0 ? copyright : author);
        rv.addField(FieldKey.COMMENT, comment);
    } catch (FieldDataInvalidException fdie) {
        throw new RuntimeException(fdie);
    }
    return rv;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:21,代码来源:RealFileReader.java

示例4: isValidHeader

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
public static boolean isValidHeader(FileChannel fc) throws IOException, CannotReadException
{
    if (fc.size() - fc.position() < HEADER_LENGTH)
    {
        throw new CannotReadException("This is not a WAV File (<12 bytes)");
    }
    ByteBuffer headerBuffer = Utils.readFileDataIntoBufferLE(fc, HEADER_LENGTH);
    if(Utils.readFourBytesAsChars(headerBuffer).equals(RIFF_SIGNATURE))
    {
        headerBuffer.getInt(); //Size
        if(Utils.readFourBytesAsChars(headerBuffer).equals(WAVE_SIGNATURE))
        {
            return true;
        }
    }
    return false;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:18,代码来源:WavRIFFHeader.java

示例5: calculateTrackLength

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Calculate track length, done it here because requires data from multiple chunks
 *
 * @param info
 * @throws CannotReadException
 */
private void calculateTrackLength(GenericAudioHeader info) throws CannotReadException {
    //If we have fact chunk we can calculate accurately by taking total of samples (per channel) divided by the number
    //of samples taken per second (per channel)
    if (info.getNoOfSamples() != null) {
        if (info.getSampleRateAsNumber() > 0) {
            info.setPreciseLength((float) info.getNoOfSamples() / info.getSampleRateAsNumber());
        }
    }
    //Otherwise adequate to divide the total number of sampling bytes by the average byte rate
    else if (info.getAudioDataLength() > 0) {
        info.setPreciseLength((float) info.getAudioDataLength() / info.getByteRate());
    } else {
        throw new CannotReadException(loggingName + " Wav Data Header Missing");
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:22,代码来源:WavInfoReader.java

示例6: delete

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
public void delete(RandomAccessFile raf, RandomAccessFile tempRaf) throws IOException, CannotReadException, CannotWriteException
{
    try
    {
        reader.read(raf);
    }
    catch (CannotReadException e)
    {
        write(VorbisCommentTag.createNewTag(), raf, tempRaf);
        return;
    }

    VorbisCommentTag emptyTag = VorbisCommentTag.createNewTag();

    //Go back to start of file
    raf.seek(0);
    write(emptyTag, raf, tempRaf);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:19,代码来源:OggVorbisTagWriter.java

示例7: readChunk

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
public static RealChunk readChunk(RandomAccessFile raf)
        throws CannotReadException, IOException {
    final String id = Utils.readString(raf, 4);
    final int size = Utils.readUint32AsInt(raf);
    if (size < 8) {
        throw new CannotReadException(
                "Corrupt file: RealAudio chunk length at position "
                        + (raf.getFilePointer() - 4)
                        + " cannot be less than 8");
    }
    if (size > (raf.length() - raf.getFilePointer() + 8)) {
        throw new CannotReadException(
                "Corrupt file: RealAudio chunk length of " + size
                        + " at position " + (raf.getFilePointer() - 4)
                        + " extends beyond the end of the file");
    }
    final byte[] bytes = new byte[size - 8];
    raf.readFully(bytes);
    return new RealChunk(id, size, bytes);
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:21,代码来源:RealChunk.java

示例8: summarizeOggPageHeaders

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Summarize all the ogg headers in a file
 *
 * A useful utility function
 *
 * @param oggFile
 * @throws CannotReadException
 * @throws IOException
 */
public void summarizeOggPageHeaders(File oggFile) throws CannotReadException, IOException
{
    RandomAccessFile raf = new RandomAccessFile(oggFile, "r");

    while (raf.getFilePointer() < raf.length())
    {
        System.out.println("pageHeader starts at absolute file position:" + raf.getFilePointer());
        OggPageHeader pageHeader = OggPageHeader.read(raf);
        System.out.println("pageHeader finishes at absolute file position:" + raf.getFilePointer());
        System.out.println(pageHeader + "\n");
        raf.seek(raf.getFilePointer() + pageHeader.getPageLength());
    }
    System.out.println("Raf File Pointer at:" + raf.getFilePointer() + "File Size is:" + raf.length());
    raf.close();
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:25,代码来源:OggFileReader.java

示例9: getEncodingInfo

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
@Override
protected GenericAudioHeader getEncodingInfo(RandomAccessFile raf) throws CannotReadException, IOException {
    final GenericAudioHeader rv = new GenericAudioHeader();
    final RealChunk prop = findPropChunk(raf);
    final DataInputStream dis = prop.getDataInputStream();
    final int objVersion = Utils.readUint16(dis);
    if (objVersion == 0) {
        final long maxBitRate = Utils.readUint32(dis) / 1000;
        final long avgBitRate = Utils.readUint32(dis) / 1000;
        final long maxPacketSize = Utils.readUint32(dis);
        final long avgPacketSize = Utils.readUint32(dis);
        final long packetCnt = Utils.readUint32(dis);
        final int duration = Utils.readUint32AsInt(dis) / 1000;
        final long preroll = Utils.readUint32(dis);
        final long indexOffset = Utils.readUint32(dis);
        final long dataOffset = Utils.readUint32(dis);
        final int numStreams = Utils.readUint16(dis);
        final int flags = Utils.readUint16(dis);
        rv.setBitrate((int) avgBitRate);
        rv.setLength(duration);
        rv.setVariableBitRate(maxBitRate != avgBitRate);
    }
    return rv;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:25,代码来源:RealFileReader.java

示例10: readRawPacketData

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Retrieve the raw VorbisComment packet data, does not include the OggVorbis header
 *
 * @param raf
 * @return
 * @throws CannotReadException if unable to find vorbiscomment header
 * @throws IOException
 */
public byte[] readRawPacketData(RandomAccessFile raf) throws CannotReadException, IOException {
    logger.fine("Read 1st page");
    //1st page = codec infos
    OggPageHeader pageHeader = OggPageHeader.read(raf);
    //Skip over data to end of page header 1
    raf.seek(raf.getFilePointer() + pageHeader.getPageLength());

    logger.fine("Read 2nd page");
    //2nd page = comment, may extend to additional pages or not , may also have setup header
    pageHeader = OggPageHeader.read(raf);

    //Now at start of packets on page 2 , check this is the vorbis comment header 
    byte[] b = new byte[VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH];
    raf.read(b);
    if (!isVorbisCommentHeader(b)) {
        throw new CannotReadException("Cannot find comment block (no vorbiscomment header)");
    }

    //Convert the comment raw data which maybe over many pages back into raw packet
    byte[] rawVorbisCommentData = convertToVorbisCommentPacket(pageHeader, raf);
    return rawVorbisCommentData;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:31,代码来源:OggVorbisTagReader.java

示例11: read

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Read next PageHeader from Buffer
 *
 * @param byteBuffer
 * @return
 * @throws IOException
 * @throws CannotReadException
 */
public static OggPageHeader read(ByteBuffer byteBuffer) throws IOException, CannotReadException
   {
       //byteBuffer
       int start = byteBuffer.position();
       logger.fine("Trying to read OggPage at:" + start);

       byte[] b = new byte[OggPageHeader.CAPTURE_PATTERN.length];
       byteBuffer.get(b);
       if (!(Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN)))
       {
           throw new CannotReadException(ErrorMessage.OGG_HEADER_CANNOT_BE_FOUND.getMsg(new String(b)));
       }

       byteBuffer.position(start + OggPageHeader.FIELD_PAGE_SEGMENTS_POS);
       int pageSegments = byteBuffer.get() & 0xFF; //unsigned
       byteBuffer.position(start);

       b = new byte[OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageSegments];
       byteBuffer.get(b);
       OggPageHeader pageHeader = new OggPageHeader(b);

       //Now just after PageHeader, ready for Packet Data
       return pageHeader;
   }
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:33,代码来源:OggPageHeader.java

示例12: countMetaBlocks

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Count the number of metadatablocks, useful for debugging
 *
 * @param f
 * @return
 * @throws CannotReadException
 * @throws IOException
 */
public int countMetaBlocks(File f) throws CannotReadException, IOException {
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    FlacStreamReader flacStream = new FlacStreamReader(raf);
    flacStream.findStream();


    boolean isLastBlock = false;

    int count = 0;
    while (!isLastBlock) {
        MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
        logger.config("Found block:" + mbh.getBlockType());
        raf.seek(raf.getFilePointer() + mbh.getDataLength());
        isLastBlock = mbh.isLastBlock();
        mbh = null; //Free memory
        count++;
    }
    raf.close();
    return count;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:29,代码来源:FlacInfoReader.java

示例13: shortSummarizeOggPageHeaders

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Summarizes the first five pages, normally all we are interested in
 *
 * @param oggFile
 * @throws CannotReadException
 * @throws IOException
 */
public void shortSummarizeOggPageHeaders(File oggFile) throws CannotReadException, IOException {
    RandomAccessFile raf = new RandomAccessFile(oggFile, "r");

    int i = 0;
    while (raf.getFilePointer() < raf.length()) {
        System.out.println("pageHeader starts at absolute file position:" + raf.getFilePointer());
        OggPageHeader pageHeader = OggPageHeader.read(raf);
        System.out.println("pageHeader finishes at absolute file position:" + raf.getFilePointer());
        System.out.println(pageHeader + "\n");
        raf.seek(raf.getFilePointer() + pageHeader.getPageLength());
        i++;
        if (i >= 5) {
            break;
        }
    }
    System.out.println("Raf File Pointer at:" + raf.getFilePointer() + "File Size is:" + raf.length());
    raf.close();
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:26,代码来源:OggFileReader.java

示例14: processData

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
public void processData() throws CannotReadException
{
    //Skip version/other flags
    dataBuffer.position(dataBuffer.position() + OTHER_FLAG_LENGTH);
    dataBuffer.order(ByteOrder.BIG_ENDIAN);

    maxSamplePerFrame   = dataBuffer.getInt();
    unknown1            = Utils.u(dataBuffer.get());
    sampleSize          = Utils.u(dataBuffer.get());
    historyMult         = Utils.u(dataBuffer.get());
    initialHistory      = Utils.u(dataBuffer.get());
    kModifier           = Utils.u(dataBuffer.get());
    channels            = Utils.u(dataBuffer.get());
    unknown2            = dataBuffer.getShort();
    maxCodedFrameSize   = dataBuffer.getInt();
    bitRate             = dataBuffer.getInt();
    sampleRate          = dataBuffer.getInt();
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:19,代码来源:Mp4AlacBox.java

示例15: delete

import org.jaudiotagger.audio.exceptions.CannotReadException; //导入依赖的package包/类
/**
 * Delete the tag (if any) present in the given file
 *
 * @param af The file to process
 *
 * @throws CannotWriteException if anything went wrong
 * @throws org.jaudiotagger.audio.exceptions.CannotReadException
 */
@Override
public void delete(AudioFile af) throws CannotReadException, CannotWriteException
{
    File file = af.getFile();

    if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite())
    {
        throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED
                .getMsg(file.getAbsolutePath()));
    }

    if (af.getFile().length() <= MINIMUM_FILESIZE)
    {
        throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED_BECAUSE_FILE_IS_TOO_SMALL
                .getMsg(file));
    }
    deleteTag(af.getTag(), file);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:27,代码来源:AudioFileWriter2.java


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