/// <exception cref="Mp3net.InvalidDataException"></exception> protected internal override void UnpackFrameData(byte[] bytes) { string filetype; try { filetype = BufferTools.ByteBufferToString(bytes, 1, 3); } catch (UnsupportedEncodingException) { filetype = "unknown"; } mimeType = "image/" + filetype.ToLower(); 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], string.Empty); marker = 1; } imageData = BufferTools.CopyBuffer(bytes, marker, bytes.Length - marker); }
public virtual void TestShouldEncodeAndDecodeISO8859_1Text() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, TEST_STRING); Assert.AreEqual(EncodedText.CHARSET_ISO_8859_1, encodedText.GetCharacterSet()); Assert.AreEqual(TEST_STRING, encodedText.ToString()); EncodedText encodedText2; byte[] bytes; // no bom & no terminator bytes = encodedText.ToBytes(); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & no terminator bytes = encodedText.ToBytes(true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // no bom & terminator bytes = encodedText.ToBytes(false, true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1 + " 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & terminator bytes = encodedText.ToBytes(true, true); Assert.AreEqual(TEST_STRING_HEX_ISO8859_1 + " 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, bytes); Assert.AreEqual(encodedText, encodedText2); }
public ID3v2UrlFrameData(bool unsynchronisation, EncodedText description, string url) : base(unsynchronisation) { this.description = description; this.url = url; }
public ID3v2CommentFrameData(bool unsynchronisation, string language, EncodedText description, EncodedText comment) : base(unsynchronisation) { this.language = language; this.description = description; this.comment = comment; }
public ID3v2PictureFrameData(bool unsynchronisation, string mimeType, byte pictureType , EncodedText description, byte[] imageData) : base(unsynchronisation) { this.mimeType = mimeType; this.pictureType = pictureType; this.description = description; this.imageData = imageData; }
public virtual void TestShouldConstructFromStringOrBytes() { EncodedText encodedText; EncodedText encodedText2; encodedText = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, TEST_STRING); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, TestHelper.HexStringToBytes(TEST_STRING_HEX_ISO8859_1)); Assert.AreEqual(encodedText, encodedText2); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, UNICODE_TEST_STRING); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes(UNICODE_TEST_STRING_HEX_UTF8)); Assert.AreEqual(encodedText, encodedText2); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16, UNICODE_TEST_STRING); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16, TestHelper.HexStringToBytes(UNICODE_TEST_STRING_HEX_UTF16LE)); Assert.AreEqual(encodedText, encodedText2); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, UNICODE_TEST_STRING); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, TestHelper.HexStringToBytes(UNICODE_TEST_STRING_HEX_UTF16BE)); Assert.AreEqual(encodedText, encodedText2); }
public virtual void SetDescription(EncodedText description) { this.description = description; }
public virtual void TestShouldEncodeAndDecodeUTF16BEText() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, UNICODE_TEST_STRING); Assert.AreEqual(EncodedText.CHARSET_UTF_16BE, encodedText.GetCharacterSet()); Assert.AreEqual(UNICODE_TEST_STRING, encodedText.ToString()); byte[] bytes; EncodedText encodedText2; // no bom & no terminator bytes = encodedText.ToBytes(); Assert.AreEqual(UNICODE_TEST_STRING_HEX_UTF16BE, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & no terminator bytes = encodedText.ToBytes(true); Assert.AreEqual("fe ff " + UNICODE_TEST_STRING_HEX_UTF16BE, TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // no bom & terminator bytes = encodedText.ToBytes(false, true); Assert.AreEqual(UNICODE_TEST_STRING_HEX_UTF16BE + " 00 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); // bom & terminator bytes = encodedText.ToBytes(true, true); Assert.AreEqual("fe ff " + UNICODE_TEST_STRING_HEX_UTF16BE + " 00 00", TestHelper.BytesToHexString(bytes)); encodedText2 = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16BE, bytes); Assert.AreEqual(encodedText, encodedText2); }
public virtual void SetComment(EncodedText comment) { this.comment = comment; }
public virtual void TestShouldDetectUTF8EncodingFromBytesWithBOM() { EncodedText encodedText = new EncodedText(TestHelper.HexStringToBytes("ef bb bf " + UNICODE_TEST_STRING_HEX_UTF8)); Assert.AreEqual(EncodedText.TEXT_ENCODING_UTF_8, encodedText.GetTextEncoding()); }
public virtual void TestShouldUseAppropriateEncodingWhenConstructingFromStringOnly() { EncodedText encodedText; string s; encodedText = new EncodedText(TEST_STRING); s = encodedText.ToString(); Assert.IsNotNull(s); encodedText = new EncodedText(UNICODE_TEST_STRING); s = encodedText.ToString(); Assert.IsNotNull(s); }
public virtual void TestShouldTranscodeFromOneEncodingToAnother() { EncodedText encodedText; encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_ISO_8859_1, true); Assert.AreEqual("43 61 66 e9 20 50 61 72 61 64 69 73 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_8, true); Assert.AreEqual("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_16, true); Assert.AreEqual("43 00 61 00 66 00 e9 00 20 00 50 00 61 00 72 00 61 00 64 00 69 00 73 00 6f 00", TestHelper.BytesToHexString(encodedText.ToBytes())); encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_UTF_16BE, true); Assert.AreEqual("00 43 00 61 00 66 00 e9 00 20 00 50 00 61 00 72 00 61 00 64 00 69 00 73 00 6f", TestHelper.BytesToHexString(encodedText.ToBytes())); }
/// <exception cref="Mp3net.InvalidDataException"></exception> protected internal override void UnpackFrameData(byte[] bytes) { try { language = BufferTools.ByteBufferToString(bytes, 1, 3); } catch (UnsupportedEncodingException) { language = string.Empty; } 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], string.Empty); marker = 4; } comment = new EncodedText(bytes[0], BufferTools.CopyBuffer(bytes, marker, bytes.Length - marker)); }
public virtual void TestShouldThrowAnExceptionWhenAttemptingToTranscodeToACharacterSetWithUnmappableCharacters() { EncodedText encodedText; encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, UNICODE_TEST_STRING); try { encodedText.SetTextEncoding(EncodedText.TEXT_ENCODING_ISO_8859_1, true); Assert.Fail("CharacterCodingException expected but not thrown"); } catch (CharacterCodingException) { } }
public virtual void TestShouldStillReturnBytesWhenStringIsEmpty() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_ISO_8859_1, string.Empty); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(false, false))); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(true, false))); Assert.IsTrue(Arrays.Equals(new byte[] { 0 }, encodedText.ToBytes(false, true))); Assert.IsTrue(Arrays.Equals(new byte[] { 0 }, encodedText.ToBytes(true, true))); }
/// <exception cref="Mp3net.InvalidDataException"></exception> protected internal override void UnpackFrameData(byte[] bytes) { int marker = BufferTools.IndexOfTerminator(bytes, 1, 1); if (marker >= 0) { try { mimeType = BufferTools.ByteBufferToString(bytes, 1, marker - 1); } catch (UnsupportedEncodingException) { 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], string.Empty); marker2 = marker; } imageData = BufferTools.CopyBuffer(bytes, marker2, bytes.Length - marker2); }
public virtual void TestShouldReturnNullWhenDecodingInvalidString() { string s = "Not unicode"; byte[] notUnicode = BufferTools.StringToByteBuffer(s, 0, s.Length); EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16, notUnicode); Assert.IsNull(encodedText.ToString()); }
public virtual void TestShouldInferISO8859_1EncodingFromBytesWithNoBOM() { EncodedText encodedText = new EncodedText(TestHelper.HexStringToBytes(TEST_STRING_HEX_ISO8859_1)); Assert.AreEqual(EncodedText.TEXT_ENCODING_ISO_8859_1, encodedText .GetTextEncoding()); }
public virtual void TestShouldHandleBacktickCharacterInString() { EncodedText encodedText = new EncodedText(unchecked((byte)0), BUFFER_WITH_A_BACKTICK); Assert.AreEqual("I" + (char)(96) + "m", encodedText.ToString()); }
/// <exception cref="Mp3net.InvalidDataException"></exception> protected internal override void UnpackFrameData(byte[] bytes) { 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], string.Empty); marker = 1; } try { url = BufferTools.ByteBufferToString(bytes, marker, bytes.Length - marker); } catch (UnsupportedEncodingException) { url = string.Empty; } }
public virtual void TestShouldThrowExceptionWhenTranscodingWithInvalidCharacterSet() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_8, TestHelper.HexStringToBytes("43 61 66 c3 a9 20 50 61 72 61 64 69 73 6f")); try { encodedText.SetTextEncoding(unchecked((byte)4), true); Assert.Fail("IllegalArgumentException expected but not thrown"); } catch (ArgumentException e) { Assert.AreEqual("Invalid text encoding 4", e.Message); } }
public virtual void TestShouldStillReturnBytesWhenUnicodeStringIsEmpty() { EncodedText encodedText = new EncodedText(EncodedText.TEXT_ENCODING_UTF_16, string.Empty); Assert.IsTrue(Arrays.Equals(new byte[] { }, encodedText.ToBytes(false, false))); Assert.IsTrue(Arrays.Equals(new byte[] { unchecked((byte)unchecked((int)(0xff))), unchecked((byte)unchecked((int)(0xfe))) }, encodedText.ToBytes(true, false))); Assert.IsTrue(Arrays.Equals(new byte[] { 0, 0 }, encodedText.ToBytes(false, true))); Assert.IsTrue(Arrays.Equals(new byte[] { unchecked((byte)unchecked((int)(0xff))), unchecked((byte)unchecked((int)(0xfe))), 0, 0 }, encodedText.ToBytes(true, true))); }
public ID3v2ObseletePictureFrameData(bool unsynchronisation, string mimeType, byte pictureType, EncodedText description, byte[] imageData) : base(unsynchronisation , mimeType, pictureType, description, imageData) { }