/** Backward compatibility test. */ @Test public void testLatin1() { CodeFunctions functions = CodeFunctions.createEncoderForLBL("latin1"); assertEquals("code page", 1252, functions.getCodepage()); assertEquals("encoding type", 9, functions.getEncodingType()); StringBuilder sb = new StringBuilder(); for (char c = 1; c < 256; c++) { sb.append(c); } CharacterEncoder encoder = functions.getEncoder(); EncodedText text = encoder.encodeText(sb.toString()); // This encoder appends a null byte. assertEquals("length of encoded text", 256, text.getLength()); for (int i = 1; i < 256; i++) { // The following characters do not display on my GPS. This covers // the region where windows-1252 differs from iso 8859 so we don't // really know which it is meant to be. if (i >= 0x80 && i <= 0xbf) continue; assertEquals("character", i, text.getCtext()[i - 1] & 0xff); } }
protected int getLength() { int length = 1; if (description != null) length += description.toBytes(true, true).length; else length++; if (url != null) length += url.length(); return length; }
/** * Transliteration when going to ascii in format 6. This was originally the only place where * transliteration was available. */ @Test public void testTransliterateLatin() { CodeFunctions functions = CodeFunctions.createEncoderForLBL("latin1"); CharacterEncoder encoder = functions.getEncoder(); EncodedText text = encoder.encodeText("Körnerstraße, Velkomezeříčská, Skólavörðustigur"); CharacterDecoder decoder = functions.getDecoder(); byte[] ctext = text.getCtext(); for (int i = 0; i < text.getLength(); i++) { decoder.addByte(ctext[i]); } String result = decoder.getText().getText(); assertEquals("transliterated text", "Körnerstraße, Velkomezerícská, Skólavörðustigur", result); }
/** * Transliteration when going to ascii in format 6. This was originally the only place where * transliteration was available. */ @Test public void testTransliterate6() { CodeFunctions functions = CodeFunctions.createEncoderForLBL(6); CharacterEncoder encoder = functions.getEncoder(); EncodedText text = encoder.encodeText("Körnerstraße, Velkomezeříčská, Skólavörðustigur"); CharacterDecoder decoder = functions.getDecoder(); byte[] ctext = text.getCtext(); for (int i = 0; i < text.getLength(); i++) { decoder.addByte(ctext[i]); } decoder.addByte(0xff); String result = decoder.getText().getText(); assertEquals("transliterated text", "KORNERSTRASSE, VELKOMEZERICSKA, SKOLAVORDUSTIGUR", result); }
protected int getLength() { int length = 4; if (mimeType != null) length += mimeType.length(); if (description != null) length += description.toBytes().length; if (imageData != null) length += imageData.length; return length; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; }
/** Quick check of the ascii 6 bit format conversion. */ @Test public void testFormat6() { CodeFunctions functions = CodeFunctions.createEncoderForLBL(6); assertEquals("code page", 0, functions.getCodepage()); assertEquals("encoding type", 6, functions.getEncodingType()); CharacterEncoder enc = functions.getEncoder(); EncodedText etext = enc.encodeText("hello world"); byte[] ctext = etext.getCtext(); int len = etext.getLength(); // This was determined from the behaviour of the existing code, and not // from first principles. assertEquals("encoded length", 9, len); byte[] foo = { 0x20, 0x53, 0xc, 0x3c, 0x5, 0xffffffcf, 0x48, 0xffffffc1, 0x3f, }; assertArrayEquals("encoded text", foo, Arrays.copyOf(ctext, len)); }
protected byte[] packFrameData() { byte[] bytes = new byte[getLength()]; if (description != null) bytes[0] = description.getTextEncoding(); else bytes[0] = 0; int marker = 1; if (description != null) { byte[] descriptionBytes = description.toBytes(true, true); BufferTools.copyIntoByteBuffer(descriptionBytes, 0, descriptionBytes.length, bytes, marker); marker += descriptionBytes.length; } else { bytes[marker++] = 0; } if (url != null && url.length() > 0) { try { BufferTools.stringIntoByteBuffer(url, 0, url.length(), bytes, marker); } catch (UnsupportedEncodingException e) { } } return bytes; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ID3v2UrlFrameData other = (ID3v2UrlFrameData) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; }
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 = ""; } }
protected byte[] packFrameData() { byte[] bytes = new byte[getLength()]; if (description != null) bytes[0] = description.getTextEncoding(); else bytes[0] = 0; int mimeTypeLength = 0; if (mimeType != null && mimeType.length() > 0) { mimeTypeLength = mimeType.length(); BufferTools.stringIntoByteBuffer(mimeType, 0, mimeTypeLength, bytes, 1); } bytes[mimeTypeLength + 1] = 0; bytes[mimeTypeLength + 2] = pictureType; int descriptionLength = 0; if (description != null && description.toBytes().length > 0) { descriptionLength = description.toBytes().length; BufferTools.copyIntoByteBuffer( description.toBytes(), 0, descriptionLength, bytes, mimeTypeLength + 3); } bytes[mimeTypeLength + descriptionLength + 3] = 0; if (imageData != null && imageData.length > 0) { BufferTools.copyIntoByteBuffer( imageData, 0, imageData.length, bytes, mimeTypeLength + descriptionLength + 4); } return bytes; }
public boolean equals(Object obj) { if (!(obj instanceof ID3v2PictureFrameData)) return false; if (!super.equals(obj)) return false; ID3v2PictureFrameData other = (ID3v2PictureFrameData) obj; if (pictureType != other.pictureType) return false; if (mimeType == null) { if (other.mimeType != null) return false; } else if (other.mimeType == null) return false; else if (!mimeType.equals(other.mimeType)) return false; if (description == null) { if (other.description != null) return false; } else if (other.description == null) return false; else if (!description.equals(other.description)) return false; if (imageData == null) { if (other.imageData != null) return false; } else if (other.imageData == null) return false; else if (!Arrays.equals(imageData, other.imageData)) return false; return true; }