@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { String filetype; try { filetype = BufferTools.byteBufferToString(bytes, 1, 3); } catch (UnsupportedEncodingException e) { filetype = "unknown"; } mimeType = "image/" + filetype.toLowerCase(); pictureType = bytes[4]; int marker = BufferTools.indexOfTerminatorForEncoding(bytes, 5, bytes[0]); if (marker >= 0) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, 5, marker - 5)); marker += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker = 1; } imageData = BufferTools.copyBuffer(bytes, marker, bytes.length - marker); } }
private void packHeader(byte[] bytes, int i) { try { BufferTools.stringIntoByteBuffer(id, 0, id.length(), bytes, 0); } catch (UnsupportedEncodingException e) { } BufferTools.copyIntoByteBuffer(packDataLength(), 0, 4, bytes, 4); BufferTools.copyIntoByteBuffer(packFlags(), 0, 2, bytes, 8); }
private boolean isXingFrame(byte[] bytes, int offset) { if (bytes.length >= offset + XING_MARKER_OFFSET_1 + 3) { if ("Xing".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_1, 4))) return true; if ("Info".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_1, 4))) return true; if (bytes.length >= offset + XING_MARKER_OFFSET_2 + 3) { if ("Xing".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_2, 4))) return true; if ("Info".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_2, 4))) return true; if (bytes.length >= offset + XING_MARKER_OFFSET_3 + 3) { if ("Xing".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_3, 4))) return true; if ("Info".equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, offset + XING_MARKER_OFFSET_3, 4))) return true; } } } return false; }
private int packExtendedHeader(byte[] bytes, int offset) { BufferTools.packSynchsafeInteger(extendedHeaderLength, bytes, offset); BufferTools.copyIntoByteBuffer(extendedHeaderData, 0, extendedHeaderData.length, bytes, offset + 4); return offset + 4 + extendedHeaderData.length; }
private int unpackExtendedHeader(byte[] bytes, int offset) { extendedHeaderLength = BufferTools.unpackSynchsafeInteger(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]) + 4; extendedHeaderData = BufferTools.copyBuffer(bytes, offset + 4, extendedHeaderLength); return extendedHeaderLength; }
private void unpackTag(byte[] bytes) throws NoSuchTagException { sanityCheckTag(bytes); title = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, TITLE_OFFSET, TITLE_LENGTH)); artist = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, ARTIST_OFFSET, ARTIST_LENGTH)); album = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, ALBUM_OFFSET, ALBUM_LENGTH)); year = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, YEAR_OFFSET, YEAR_LENGTH)); genre = bytes[GENRE_OFFSET] & 0xFF; if (genre == 0xFF) { genre = -1; } if (bytes[TRACK_MARKER_OFFSET] != 0) { comment = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, COMMENT_OFFSET, COMMENT_LENGTH_V1_0)); track = null; } else { comment = BufferTools.trimStringRight(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, COMMENT_OFFSET, COMMENT_LENGTH_V1_1)); int trackInt = bytes[TRACK_OFFSET]; if (trackInt == 0) { track = ""; } else { track = Integer.toString(trackInt); } } }
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { int marker = BufferTools.indexOfTerminator(bytes, 1, 1); if (marker >= 0) { try { mimeType = BufferTools.byteBufferToString(bytes, 1, marker - 1); } catch (UnsupportedEncodingException e) { mimeType = "image/unknown"; } } else { mimeType = "image/unknown"; } pictureType = bytes[marker + 1]; marker += 2; int marker2 = BufferTools.indexOfTerminatorForEncoding(bytes, marker, bytes[0]); if (marker2 >= 0) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, marker, marker2 - marker)); marker2 += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker2 = marker; } imageData = BufferTools.copyBuffer(bytes, marker2, bytes.length - marker2); }
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { try { url = BufferTools.byteBufferToString(bytes, 0, bytes.length); } catch (UnsupportedEncodingException e) { url = ""; } }
langPadded = language.substring(0, 3); } else { langPadded = BufferTools.padStringRight(language, 3, '\00'); BufferTools.stringIntoByteBuffer(langPadded, 0, 3, bytes, 1); } catch (UnsupportedEncodingException e) { if (description != null) { byte[] descriptionBytes = description.toBytes(true, true); BufferTools.copyIntoByteBuffer(descriptionBytes, 0, descriptionBytes.length, bytes, marker); marker += descriptionBytes.length; } else { byte[] terminatorBytes = comment != null ? comment.getTerminator() : new byte[]{0}; BufferTools.copyIntoByteBuffer(terminatorBytes, 0, terminatorBytes.length, bytes, marker); marker += terminatorBytes.length; BufferTools.copyIntoByteBuffer(commentBytes, 0, commentBytes.length, bytes, marker);
public void packFrame(byte[] bytes, int offset) throws NotSupportedException { packHeader(bytes, offset); BufferTools.copyIntoByteBuffer(data, 0, data.length, bytes, offset + HEADER_LENGTH); }
private void showCustomTag(StringBuffer buffer) { buffer.append("Custom Tag\n"); byte[] bytes = mp3file.getCustomTag(); if (bytes == null) { buffer.append(" NONE!\n"); } else { int length = Math.min(bytes.length, MAX_CUSTOM_TAG_BYTES_TO_SHOW); try { String s = BufferTools.byteBufferToString(bytes, 0, length); showLastField(buffer, "Data", BufferTools.asciiOnly(s), bytes.length > MAX_CUSTOM_TAG_BYTES_TO_SHOW ? "..." : null); } catch (UnsupportedEncodingException e) { buffer.append(" ?\n"); } } }
private int packHeader(byte[] bytes, int offset) { try { BufferTools.stringIntoByteBuffer(TAG, 0, TAG.length(), bytes, offset); } catch (UnsupportedEncodingException e) { } String s[] = version.split("\\."); if (s.length > 0) { byte majorVersion = Byte.parseByte(s[0]); bytes[offset + MAJOR_VERSION_OFFSET] = majorVersion; } if (s.length > 1) { byte minorVersion = Byte.parseByte(s[1]); bytes[offset + MINOR_VERSION_OFFSET] = minorVersion; } packFlags(bytes, offset); BufferTools.packSynchsafeInteger(getDataLength(), bytes, offset + DATA_LENGTH_OFFSET); return offset + HEADER_LENGTH; }
@Override protected void unpackFlags(byte[] buffer) { unsynchronisation = BufferTools.checkBit(buffer[FLAGS_OFFSET], UNSYNCHRONISATION_BIT); extendedHeader = BufferTools.checkBit(buffer[FLAGS_OFFSET], EXTENDED_HEADER_BIT); experimental = BufferTools.checkBit(buffer[FLAGS_OFFSET], EXPERIMENTAL_BIT); footer = BufferTools.checkBit(buffer[FLAGS_OFFSET], FOOTER_BIT); }
public static int indexOfTerminatorForEncoding(byte[] bytes, int fromIndex, int encoding) { int terminatorLength = (encoding == EncodedText.TEXT_ENCODING_UTF_16 || encoding == EncodedText.TEXT_ENCODING_UTF_16BE) ? 2 : 1; return indexOfTerminator(bytes, fromIndex, terminatorLength); } }
protected static byte[] charBufferToBytes(CharBuffer charBuffer, String characterSet) throws CharacterCodingException { Charset charset = Charset.forName(characterSet); CharsetEncoder encoder = charset.newEncoder(); ByteBuffer byteBuffer = encoder.encode(charBuffer); return BufferTools.copyBuffer(byteBuffer.array(), 0, byteBuffer.limit()); } }
public static byte[] packSynchsafeInteger(int i) { byte[] bytes = new byte[4]; packSynchsafeInteger(i, bytes, 0); return bytes; }
protected byte[] packDataLength() { return BufferTools.packInteger(dataLength); }
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { int marker = BufferTools.indexOfTerminator(bytes, 1, 1); if (marker >= 0) { try { mimeType = BufferTools.byteBufferToString(bytes, 1, marker - 1); } catch (UnsupportedEncodingException e) { mimeType = "image/unknown"; } } else { mimeType = "image/unknown"; } pictureType = bytes[marker + 1]; marker += 2; int marker2 = BufferTools.indexOfTerminatorForEncoding(bytes, marker, bytes[0]); if (marker2 >= 0) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, marker, marker2 - marker)); marker2 += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker2 = marker; } imageData = BufferTools.copyBuffer(bytes, marker2, bytes.length - marker2); }
public static String byteBufferToStringIgnoringEncodingIssues(byte[] bytes, int offset, int length) { try { return byteBufferToString(bytes, offset, length, defaultCharsetName); } catch (UnsupportedEncodingException e) { return null; } }
langPadded = language.substring(0, 3); } else { langPadded = BufferTools.padStringRight(language, 3, '\00'); BufferTools.stringIntoByteBuffer(langPadded, 0, 3, bytes, 1); } catch (UnsupportedEncodingException e) { if (description != null) { byte[] descriptionBytes = description.toBytes(true, true); BufferTools.copyIntoByteBuffer(descriptionBytes, 0, descriptionBytes.length, bytes, marker); marker += descriptionBytes.length; } else { byte[] terminatorBytes = comment != null ? comment.getTerminator() : new byte[]{0}; BufferTools.copyIntoByteBuffer(terminatorBytes, 0, terminatorBytes.length, bytes, marker); marker += terminatorBytes.length; BufferTools.copyIntoByteBuffer(commentBytes, 0, commentBytes.length, bytes, marker);