private int maxEndOffset() { int maxEndOffset = (int) getLength(); if (hasId3v1Tag()) maxEndOffset -= ID3v1Tag.TAG_LENGTH; return maxEndOffset; }
private void catalogMp3Fields(StringBuffer cat) { catalogField(cat, FileUtils.extractFilename(mp3file.getFilename())); catalogField(cat, Long.toString(mp3file.getLength())); catalogField(cat, Long.toString(mp3file.getLengthInSeconds())); catalogField(cat, mp3file.getVersion()); catalogField(cat, mp3file.getLayer()); catalogField(cat, Integer.toString(mp3file.getSampleRate())); catalogField(cat, Integer.toString(mp3file.getBitrate())); catalogField(cat, vbrString(mp3file.isVbr())); catalogField(cat, mp3file.getChannelMode()); }
private void initId3v1Tag(SeekableByteChannel seekableByteChannel) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(ID3v1Tag.TAG_LENGTH); seekableByteChannel.position(getLength() - ID3v1Tag.TAG_LENGTH); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); if (bytesRead < ID3v1Tag.TAG_LENGTH) throw new IOException("Not enough bytes read"); try { id3v1Tag = new ID3v1Tag(byteBuffer.array()); } catch (NoSuchTagException e) { id3v1Tag = null; } }
private void showMp3Fields(StringBuffer buffer) { buffer.append("MP3 Data\n"); showField(buffer, "Filename", FileUtils.extractFilename(mp3file.getFilename())); showField(buffer, "Size", Long.toString(mp3file.getLength())); showField(buffer, "Length", formatTime(mp3file.getLengthInSeconds())); showField(buffer, "Version", mp3file.getVersion()); showField(buffer, "Layer", mp3file.getLayer()); showField(buffer, "Sample rate", Integer.toString(mp3file.getSampleRate()), "Hz"); showField(buffer, "Bitrate", Integer.toString(mp3file.getBitrate()), "kbps (" + vbrString(mp3file.isVbr()) + ")"); showField(buffer, "Channel mode", mp3file.getChannelMode()); }
private void initCustomTag(SeekableByteChannel seekableByteChannel) throws IOException { int bufferLength = (int) (getLength() - (endOffset + 1)); if (hasId3v1Tag()) bufferLength -= ID3v1Tag.TAG_LENGTH; if (bufferLength <= 0) { customTag = null; } else { ByteBuffer byteBuffer = ByteBuffer.allocate(bufferLength); seekableByteChannel.position(endOffset + 1); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); customTag = byteBuffer.array(); if (bytesRead < bufferLength) throw new IOException("Not enough bytes read"); } }
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"); }
private int maxEndOffset() { int maxEndOffset = (int) getLength(); if (hasId3v1Tag()) maxEndOffset -= ID3v1Tag.TAG_LENGTH; return maxEndOffset; }
private void initId3v1Tag(SeekableByteChannel seekableByteChannel) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(ID3v1Tag.TAG_LENGTH); seekableByteChannel.position(getLength() - ID3v1Tag.TAG_LENGTH); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); if (bytesRead < ID3v1Tag.TAG_LENGTH) throw new IOException("Not enough bytes read"); try { id3v1Tag = new ID3v1Tag(byteBuffer.array()); } catch (NoSuchTagException e) { id3v1Tag = null; } }
private void initCustomTag(SeekableByteChannel seekableByteChannel) throws IOException { int bufferLength = (int) (getLength() - (endOffset + 1)); if (hasId3v1Tag()) bufferLength -= ID3v1Tag.TAG_LENGTH; if (bufferLength <= 0) { customTag = null; } else { ByteBuffer byteBuffer = ByteBuffer.allocate(bufferLength); seekableByteChannel.position(endOffset + 1); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); customTag = byteBuffer.array(); if (bytesRead < bufferLength) throw new IOException("Not enough bytes read"); } }
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"); }