public byte[] toBytes(boolean includeBom, boolean includeTerminator) { characterSetForTextEncoding(textEncoding); // ensured textEncoding is valid int newLength = value.length + (includeBom ? boms[textEncoding].length : 0) + (includeTerminator ? getTerminator().length : 0); if (newLength == value.length) { return value; } else { byte bytes[] = new byte[newLength]; int i = 0; if (includeBom) { byte[] bom = boms[textEncoding]; if (bom.length > 0) { System.arraycopy(boms[textEncoding], 0, bytes, i, boms[textEncoding].length); i += boms[textEncoding].length; } } if (value.length > 0) { System.arraycopy(value, 0, bytes, i, value.length); i += value.length; } if (includeTerminator) { byte[] terminator = getTerminator(); if (terminator.length > 0) { System.arraycopy(terminator, 0, bytes, i, terminator.length); } } return bytes; } }
@Override protected int getLength() { int length = 4; if (description != null) length += description.toBytes(true, true).length; else length += comment != null ? comment.getTerminator().length : 1; if (comment != null) length += comment.toBytes(true, false).length; return length; }
@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); } }
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { int marker = BufferTools.indexOfTerminatorForEncoding(bytes, 1, bytes[0]); if (marker >= 0) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, 1, marker - 1)); marker += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker = 1; } try { url = BufferTools.byteBufferToString(bytes, marker, bytes.length - marker); } catch (UnsupportedEncodingException e) { url = ""; } }
marker += descriptionBytes.length; } else { byte[] terminatorBytes = comment != null ? comment.getTerminator() : new byte[]{0}; BufferTools.copyIntoByteBuffer(terminatorBytes, 0, terminatorBytes.length, bytes, marker); marker += terminatorBytes.length;
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { try { language = BufferTools.byteBufferToString(bytes, 1, 3); } catch (UnsupportedEncodingException e) { language = ""; } int marker = BufferTools.indexOfTerminatorForEncoding(bytes, 4, bytes[0]); if (marker >= 4) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, 4, marker - 4)); marker += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker = 4; } comment = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, marker, bytes.length - marker)); }
@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 byte[] toBytes(boolean includeBom, boolean includeTerminator) { characterSetForTextEncoding(textEncoding); // ensured textEncoding is valid int newLength = value.length + (includeBom ? boms[textEncoding].length : 0) + (includeTerminator ? getTerminator().length : 0); if (newLength == value.length) { return value; } else { byte bytes[] = new byte[newLength]; int i = 0; if (includeBom) { byte[] bom = boms[textEncoding]; if (bom.length > 0) { System.arraycopy(boms[textEncoding], 0, bytes, i, boms[textEncoding].length); i += boms[textEncoding].length; } } if (value.length > 0) { System.arraycopy(value, 0, bytes, i, value.length); i += value.length; } if (includeTerminator) { byte[] terminator = getTerminator(); if (terminator.length > 0) { System.arraycopy(terminator, 0, bytes, i, terminator.length); } } return bytes; } }
@Override protected int getLength() { int length = 4; if (description != null) length += description.toBytes(true, true).length; else length += comment != null ? comment.getTerminator().length : 1; if (comment != null) length += comment.toBytes(true, false).length; return length; }
@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); } }
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { int marker = BufferTools.indexOfTerminatorForEncoding(bytes, 1, bytes[0]); if (marker >= 0) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, 1, marker - 1)); marker += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker = 1; } try { url = BufferTools.byteBufferToString(bytes, marker, bytes.length - marker); } catch (UnsupportedEncodingException e) { url = ""; } }
marker += descriptionBytes.length; } else { byte[] terminatorBytes = comment != null ? comment.getTerminator() : new byte[]{0}; BufferTools.copyIntoByteBuffer(terminatorBytes, 0, terminatorBytes.length, bytes, marker); marker += terminatorBytes.length;
@Override protected void unpackFrameData(byte[] bytes) throws InvalidDataException { try { language = BufferTools.byteBufferToString(bytes, 1, 3); } catch (UnsupportedEncodingException e) { language = ""; } int marker = BufferTools.indexOfTerminatorForEncoding(bytes, 4, bytes[0]); if (marker >= 4) { description = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, 4, marker - 4)); marker += description.getTerminator().length; } else { description = new EncodedText(bytes[0], ""); marker = 4; } comment = new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, marker, bytes.length - marker)); }
@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); }