Package entagged.audioformats.exceptions

Examples of entagged.audioformats.exceptions.CannotReadException


    String ID3 = new String(b);

    // Check signature, if not "ID3" the file does not contain a ID3V2 tag
    // at all or the specification of ID3.org wasn't respected.
    if (!ID3.equals("ID3")) {
      throw new CannotReadException("Not an ID3 tag");
    }
    // Begins tag parsing --------------------------------------------------

    // ---------------------------------------------------------------------
    // Version of tag ID3v2.xx.xx
    String versionHigh = String.valueOf(raf.read());
    String versionID3 = versionHigh + "." + raf.read();

    // parsing the ID3V2 tag header flags.
    ID3Flags = processID3Flags(raf.readByte());
    // ---------------------------------------------------------------------
    // Read the tagsize from header, which is a sync safe integer
    int tagSize = readSyncsafeInteger(raf);

    // ---------------------------------------------------------------------
    // Fill a byte buffer, then process according to correct version
    b = new byte[tagSize + 2];
//    ByteBuffer bb = ByteBuffer.allocateDirect(tagSize+2);
    raf.readFully(b);
    ByteBuffer bb = ByteBuffer.wrap(b);
//    bb.put(b);
//    bb.position(0);
//    raf.readFully(b);
   
//     MappedByteBuffer buffer = raf.getChannel().map(MapMode.READ_ONLY,
//        raf.getFilePointer(), tagSize + 1);
//     buffer.load();
//    ByteBuffer bb = buffer;
//     ByteBuffer bb = ByteBuffer.wrap(b);

    if (ID3Flags[0] == true) {
      // We have unsynchronization, first re-synchronize
      bb = synchronizer.synchronize(bb);
    }

    // Up to now we use the same reader for all versions and pass a flag
    if (versionHigh.equals("2")) {
      tag = tagReader.read(bb, ID3Flags, Id3v2Tag.ID3V22);
    } else if (versionHigh.equals("3")) {
      tag = tagReader.read(bb, ID3Flags, Id3v2Tag.ID3V23);
    } else if (versionHigh.equals("4")) {
      tag = tagReader.read(bb, ID3Flags, Id3v2Tag.ID3V24);
    } else {
      /*
       * The implementation of entagges ID3V2 tag parsing does not ignore
       * unknown ID3V2 tag definitions, so we must throw an error.
       */
      throw new CannotReadException("ID3v2 tag version " + versionID3
          + " not supported !");
    }
    return tag;
  }
View Full Code Here


  public AudioFile readFile(File f) throws CannotReadException {
    String ext = Utils.getExtension(f);

    Object afr = readers.get(ext);
    if (afr == null)
      throw new CannotReadException(
          "No Reader associated to this extension: " + ext);

    return ((AudioFileReader) afr).read(f);
  }
View Full Code Here

   * @param f The file to read
   * @exception CannotReadException If anything went bad during the read of this file
   */
  public AudioFile read(File f) throws CannotReadException {
    if (!f.canRead())
      throw new CannotReadException("Can't read file \""+f.getAbsolutePath()+"\"");
   
    if(f.length() <= 150)
      throw new CannotReadException("Less than 150 byte \""+f.getAbsolutePath()+"\"");
   
    RandomAccessFile raf = null;
    try{
      raf = new RandomAccessFile( f, "r" );
      raf.seek( 0 );
     
      EncodingInfo info = getEncodingInfo(raf);
   
      Tag tag;
      try {
        raf.seek( 0 );
        tag = getTag(raf);
      } catch (CannotReadException e) {
        System.err.println(e.getMessage());
        tag = new GenericTag();
      }
   
      return new AudioFile(f, info, tag);
     
    } catch ( Exception e ) {
      throw new CannotReadException("\""+f+"\" :"+e,e);
    }
    finally {
        try{
          if(raf != null)
              raf.close();
View Full Code Here

    byte[] b = new byte[8];
    raf.read(b);
   
    String tagS = new String( b );
    if(!tagS.equals( "APETAGEX" )){
      throw new CannotReadException("There is no APE Tag in this file");
    }
    //Parse the tag -)------------------------------------------------
    //Version
    b = new byte[4];
    raf.read( b );
    int version = Utils.getNumber(b, 0,3);
    if(version != 2000) {
      throw new CannotReadException("APE Tag other than version 2.0 are not supported");
    }
   
    //Size
    b = new byte[4];
    raf.read( b );
    long tagSize = Utils.getLongNumber(b, 0,3);

    //Number of items
    b = new byte[4];
    raf.read( b );
    int itemNumber = Utils.getNumber(b, 0,3);
   
    //Tag Flags
    b = new byte[4];
    raf.read( b );
    //TODO handle these
   
    raf.seek(raf.length() - tagSize);
   
    for(int i = 0; i<itemNumber; i++) {
      //Content length
      b = new byte[4];
      raf.read( b );
      int contentLength = Utils.getNumber(b, 0,3);
      if(contentLength > 500000)
        throw new CannotReadException("Item size is much too large: "+contentLength+" bytes");
     
      //Item flags
      b = new byte[4];
      raf.read( b );
      //TODO handle these
View Full Code Here

    raf.seek(0);
    EncodingInfo info = new EncodingInfo();
    try {
      AsfHeader header = AsfHeaderReader.readHeader(raf);
      if (header == null) {
        throw new CannotReadException(
            "Some values must have been "
                + "incorrect for interpretation as asf with wma content.");
      }
      info.setBitrate(header.getAudioStreamChunk().getKbps());
      info.setChannelNumber((int) header.getAudioStreamChunk()
          .getChannelCount());
      info.setEncodingType("ASF (audio): "
          + header.getAudioStreamChunk().getCodecDescription());
      info.setPreciseLength(header.getFileHeader().getPreciseDuration());
      info.setSamplingRate((int) header.getAudioStreamChunk()
          .getSamplingRate());
    } catch (Exception e) {
      if (e instanceof IOException)
        throw (IOException) e;
      else if (e instanceof CannotReadException)
        throw (CannotReadException) e;
      else {
        throw new CannotReadException("Failed to read. Cause: "
            + e.getMessage());
      }
    }
    return info;
  }
View Full Code Here

    raf.seek(0);
    Tag tag = null;
    try {
      AsfHeader header = AsfHeaderReader.readHeader(raf);
      if (header == null) {
        throw new CannotReadException(
            "Some values must have been "
                + "incorrect for interpretation as asf with wma content.");
      }

      tag = TagConverter.createTagOf(header);

    } catch (Exception e) {
      if (e instanceof IOException)
        throw (IOException) e;
      else if (e instanceof CannotReadException)
        throw (CannotReadException) e;
      else {
        throw new CannotReadException("Failed to read. Cause: "
            + e.getMessage());
      }
    }
    return tag;
  }
View Full Code Here

        seek(raf, box, "meta");
       
        //4-skip the meta flags
        raf.read(b);
        if(b[0] != 0)
            throw new CannotReadException();
       
        //5-Seek the "ilst"
        seek(raf, box, "ilst");
        int length = box.getOffset() - 8;
       
View Full Code Here

TOP

Related Classes of entagged.audioformats.exceptions.CannotReadException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.