private void setVersion(int version) throws InvalidDataException { switch (version) { case 0: this.version = MPEG_VERSION_2_5; break; case 2: this.version = MPEG_VERSION_2_0; break; case 3: this.version = MPEG_VERSION_1_0; break; default: throw new InvalidDataException("Invalid mpeg audio version in frame header"); } }
private void setLayer(int layer) throws InvalidDataException { switch (layer) { case 1: this.layer = 3; break; case 2: this.layer = 2; break; case 3: this.layer = 1; break; default: throw new InvalidDataException("Invalid mpeg layer description in frame header"); } }
private void setEmphasis(int emphasis) throws InvalidDataException { switch (emphasis) { case 0: this.emphasis = EMPHASIS_NONE; break; case 1: this.emphasis = EMPHASIS__50_15_MS; break; case 3: this.emphasis = EMPHASIS_CCITT_J_17; break; default: throw new InvalidDataException("Invalid emphasis in frame header"); } }
private void setChannelMode(int channelMode) throws InvalidDataException { switch (channelMode) { case 0: this.channelMode = CHANNEL_MODE_STEREO; break; case 1: this.channelMode = CHANNEL_MODE_JOINT_STEREO; break; case 2: this.channelMode = CHANNEL_MODE_DUAL_MONO; break; case 3: this.channelMode = CHANNEL_MODE_MONO; break; default: throw new InvalidDataException("Invalid channel mode in frame header"); } }
protected void sanityCheckUnpackedHeader() throws InvalidDataException { for (int i = 0; i < id.length(); i++) { if (!((id.charAt(i) >= 'A' && id.charAt(i) <= 'Z') || (id.charAt(i) >= '0' && id.charAt(i) <= '9'))) { throw new InvalidDataException("Not a valid frame - invalid tag " + id); } } }
private int unpackFooter(byte[] bytes, int offset) throws InvalidDataException { if (!FOOTER_TAG.equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset, FOOTER_TAG.length()))) { throw new InvalidDataException("Invalid footer"); } return FOOTER_LENGTH; }
throw new InvalidDataException("Invalid mode extension in frame header");
private void sanityCheckFrame(MpegFrame frame, int offset) throws InvalidDataException { if (sampleRate != frame.getSampleRate()) throw new InvalidDataException("Inconsistent frame header"); if (!layer.equals(frame.getLayer())) throw new InvalidDataException("Inconsistent frame header"); if (!version.equals(frame.getVersion())) throw new InvalidDataException("Inconsistent frame header"); if (offset + frame.getLengthInBytes() > getLength()) throw new InvalidDataException("Frame would extend beyond end of file"); }
throw new InvalidDataException("Invalid sample rate in frame header");
public MpegFrame(byte[] frameData) throws InvalidDataException { if (frameData.length < FRAME_DATA_LENGTH) throw new InvalidDataException("Mpeg frame too short"); long frameHeader = BufferTools.unpackInteger(frameData[0], frameData[1], frameData[2], frameData[3]); setFields(frameHeader); }
throw new InvalidDataException("Invalid bitrate in frame header");
private void init(int bufferLength, boolean scanFile) throws IOException, UnsupportedTagException, InvalidDataException { if (bufferLength < MINIMUM_BUFFER_LENGTH + 1) throw new IllegalArgumentException("Buffer too small"); this.bufferLength = bufferLength; this.scanFile = scanFile; try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, StandardOpenOption.READ)) { initId3v1Tag(seekableByteChannel); scanFile(seekableByteChannel); if (startOffset < 0) { throw new InvalidDataException("No mpegs frames found"); } initId3v2Tag(seekableByteChannel); if (scanFile) { initCustomTag(seekableByteChannel); } } }
private int unpackHeader(byte[] bytes) throws UnsupportedTagException, InvalidDataException { int majorVersion = bytes[MAJOR_VERSION_OFFSET]; int minorVersion = bytes[MINOR_VERSION_OFFSET]; version = majorVersion + "." + minorVersion; if (majorVersion != 2 && majorVersion != 3 && majorVersion != 4) { throw new UnsupportedTagException("Unsupported version " + version); } unpackFlags(bytes); if ((bytes[FLAGS_OFFSET] & 0x0F) != 0) throw new UnsupportedTagException("Unrecognised bits in header"); dataLength = BufferTools.unpackSynchsafeInteger(bytes[DATA_LENGTH_OFFSET], bytes[DATA_LENGTH_OFFSET + 1], bytes[DATA_LENGTH_OFFSET + 2], bytes[DATA_LENGTH_OFFSET + 3]); if (dataLength < 1) throw new InvalidDataException("Zero size tag"); return HEADER_LENGTH; }
fileOffset = lastOffset + 1; if (fileOffset == 0) throw new InvalidDataException("Valid start of mpeg frames not found", e); seekableByteChannel.position(fileOffset); break;
private void unpackTag(byte[] bytes) throws NoSuchTagException, UnsupportedTagException, InvalidDataException { ID3v2TagFactory.sanityCheckTag(bytes); int offset = unpackHeader(bytes); try { if (extendedHeader) { offset = unpackExtendedHeader(bytes, offset); } int framesLength = dataLength; if (footer) framesLength -= 10; offset = unpackFrames(bytes, offset, framesLength); if (footer) { offset = unpackFooter(bytes, dataLength); } } catch (ArrayIndexOutOfBoundsException e) { throw new InvalidDataException("Premature end of tag", e); } }
private void setEmphasis(int emphasis) throws InvalidDataException { switch (emphasis) { case 0: this.emphasis = EMPHASIS_NONE; break; case 1: this.emphasis = EMPHASIS__50_15_MS; break; case 3: this.emphasis = EMPHASIS_CCITT_J_17; break; default: throw new InvalidDataException("Invalid emphasis in frame header"); } }
private void setLayer(int layer) throws InvalidDataException { switch (layer) { case 1: this.layer = 3; break; case 2: this.layer = 2; break; case 3: this.layer = 1; break; default: throw new InvalidDataException("Invalid mpeg layer description in frame header"); } }
private void setVersion(int version) throws InvalidDataException { switch (version) { case 0: this.version = MPEG_VERSION_2_5; break; case 2: this.version = MPEG_VERSION_2_0; break; case 3: this.version = MPEG_VERSION_1_0; break; default: throw new InvalidDataException("Invalid mpeg audio version in frame header"); } }
private void setChannelMode(int channelMode) throws InvalidDataException { switch (channelMode) { case 0: this.channelMode = CHANNEL_MODE_STEREO; break; case 1: this.channelMode = CHANNEL_MODE_JOINT_STEREO; break; case 2: this.channelMode = CHANNEL_MODE_DUAL_MONO; break; case 3: this.channelMode = CHANNEL_MODE_MONO; break; default: throw new InvalidDataException("Invalid channel mode in frame header"); } }
protected void sanityCheckUnpackedHeader() throws InvalidDataException { for (int i = 0; i < id.length(); i++) { if (!((id.charAt(i) >= 'A' && id.charAt(i) <= 'Z') || (id.charAt(i) >= '0' && id.charAt(i) <= '9'))) { throw new InvalidDataException("Not a valid frame - invalid tag " + id); } } }