@Test public void testSetStringValue() { MetadataDescriptor desc = new MetadataDescriptor( ContainerType.CONTENT_DESCRIPTION, "name", MetadataDescriptor.TYPE_STRING); desc.setStringValue(createAString(5)); Assert.assertEquals(createAString(5), desc.getString()); desc.setStringValue(createAString(0)); Assert.assertEquals(createAString(0), desc.getString()); try { desc .setStringValue(createAString(MetadataDescriptor.WORD_MAXVALUE + 1)); Assert.fail("Exception expected"); } catch (IllegalArgumentException iae) { } desc = new MetadataDescriptor(ContainerType.EXTENDED_CONTENT, "name", MetadataDescriptor.TYPE_STRING); TagOptionSingleton.getInstance().setTruncateTextWithoutErrors(true); desc .setStringValue(createAString(MetadataDescriptor.WORD_MAXVALUE + 1)); TagOptionSingleton.getInstance().setTruncateTextWithoutErrors(false); try { desc .setStringValue(createAString(MetadataDescriptor.WORD_MAXVALUE + 1)); Assert.fail("Exception expected"); } catch (IllegalArgumentException iae) { } desc = new MetadataDescriptor(ContainerType.METADATA_LIBRARY_OBJECT, "name", MetadataDescriptor.TYPE_STRING); desc .setStringValue(createAString(MetadataDescriptor.WORD_MAXVALUE + 1)); }
public void setStringValue(final String value) throws IllegalArgumentException { if (value == null) { this.content = new byte[0]; } else { final byte[] tmp = Utils.getBytes(value, AsfHeader.ASF_CHARSET); if (getContainerType().isWithinValueRange(tmp.length)) { this.content = tmp; } else { if (TagOptionSingleton.getInstance().isTruncateTextWithoutErrors()) { final int copyBytes = (int)getContainerType().getMaximumDataLength().longValue(); this.content = new byte[copyBytes % 2 == 0 ? copyBytes : copyBytes - 1]; System.arraycopy(tmp, 0, this.content, 0, this.content.length); } else { throw new IllegalArgumentException(String.format(Locale.getDefault(), WMA_LENGTH_OF_DATA_IS_TOO_LARGE, tmp.length, getContainerType().getMaximumDataLength(), getContainerType().getContainerGUID().getDescription())); } } } this.descriptorType = TYPE_STRING; }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public void setStringValue(final String value) throws IllegalArgumentException { if (value == null) { this.content = new byte[0]; } else { final byte[] tmp = Utils.getBytes(value, AsfHeader.ASF_CHARSET); if (getContainerType().isWithinValueRange(tmp.length)) { this.content = tmp; } else { if (TagOptionSingleton.getInstance().isTruncateTextWithoutErrors()) { final int copyBytes = (int)getContainerType().getMaximumDataLength().longValue(); this.content = new byte[copyBytes % 2 == 0 ? copyBytes : copyBytes - 1]; System.arraycopy(tmp, 0, this.content, 0, this.content.length); } else { throw new IllegalArgumentException(String.format(Locale.getDefault(), WMA_LENGTH_OF_DATA_IS_TOO_LARGE, tmp.length, getContainerType().getMaximumDataLength(), getContainerType().getContainerGUID().getDescription())); } } } this.descriptorType = TYPE_STRING; } }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public void setStringValue(final String value) throws IllegalArgumentException { if (value == null) { this.content = new byte[0]; } else { final byte[] tmp = Utils.getBytes(value, AsfHeader.ASF_CHARSET); if (getContainerType().isWithinValueRange(tmp.length)) { this.content = tmp; } else { if (TagOptionSingleton.getInstance().isTruncateTextWithoutErrors()) { final int copyBytes = (int)getContainerType().getMaximumDataLength().longValue(); this.content = new byte[copyBytes % 2 == 0 ? copyBytes : copyBytes - 1]; System.arraycopy(tmp, 0, this.content, 0, this.content.length); } else { throw new IllegalArgumentException(String.format(Locale.getDefault(), WMA_LENGTH_OF_DATA_IS_TOO_LARGE, tmp.length, getContainerType().getMaximumDataLength(), getContainerType().getContainerGUID().getDescription())); } } } this.descriptorType = TYPE_STRING; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public void setStringValue(final String value) throws IllegalArgumentException { if (value == null) { this.content = new byte[0]; } else { final byte[] tmp = Utils.getBytes(value, AsfHeader.ASF_CHARSET); if (getContainerType().isWithinValueRange(tmp.length)) { this.content = tmp; } else { if (TagOptionSingleton.getInstance().isTruncateTextWithoutErrors()) { final int copyBytes = (int)getContainerType().getMaximumDataLength().longValue(); this.content = new byte[copyBytes % 2 == 0 ? copyBytes : copyBytes - 1]; System.arraycopy(tmp, 0, this.content, 0, this.content.length); } else { throw new IllegalArgumentException(String.format(Locale.getDefault(), WMA_LENGTH_OF_DATA_IS_TOO_LARGE, tmp.length, getContainerType().getMaximumDataLength(), getContainerType().getContainerGUID().getDescription())); } } } this.descriptorType = TYPE_STRING; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); @Override Object clone(); int compareTo(final MetadataDescriptor other); MetadataDescriptor createCopy(); @Override boolean equals(final Object obj); boolean getBoolean(); @Deprecated byte[] getBytes(); ContainerType getContainerType(); GUID getGuid(); String getName(); long getNumber(); byte[] getRawData(); int getRawDataSize(); String getString(); int getType(); @Override int hashCode(); boolean isEmpty(); void setBinaryValue(final byte[] data); void setBooleanValue(final boolean value); void setDWordValue(final long value); void setGUIDValue(final GUID value); void setQWordValue(final long value); void setString(final String value); void setStringValue(final String value); void setWordValue(final int value); @Override String toString(); }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public void setStringValue(final String value) throws IllegalArgumentException { if (value == null) { this.content = new byte[0]; } else { final byte[] tmp = Utils.getBytes(value, AsfHeader.ASF_CHARSET); if (getContainerType().isWithinValueRange(tmp.length)) { this.content = tmp; } else { if (TagOptionSingleton.getInstance().isTruncateTextWithoutErrors()) { final int copyBytes = (int)getContainerType().getMaximumDataLength().longValue(); this.content = new byte[copyBytes % 2 == 0 ? copyBytes : copyBytes - 1]; System.arraycopy(tmp, 0, this.content, 0, this.content.length); } else { throw new IllegalArgumentException(String.format(Locale.getDefault(), WMA_LENGTH_OF_DATA_IS_TOO_LARGE, tmp.length, getContainerType().getMaximumDataLength(), getContainerType().getContainerGUID().getDescription())); } } } this.descriptorType = TYPE_STRING; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); @Override Object clone(); int compareTo(final MetadataDescriptor other); MetadataDescriptor createCopy(); @Override boolean equals(final Object obj); boolean getBoolean(); @Deprecated byte[] getBytes(); ContainerType getContainerType(); GUID getGuid(); String getName(); long getNumber(); byte[] getRawData(); int getRawDataSize(); String getString(); int getType(); @Override int hashCode(); boolean isEmpty(); void setBinaryValue(final byte[] data); void setBooleanValue(final boolean value); void setDWordValue(final long value); void setGUIDValue(final GUID value); void setQWordValue(final long value); void setString(final String value); void setStringValue(final String value); void setWordValue(final int value); @Override String toString(); static final long DWORD_MAXVALUE; static final int MAX_LANG_INDEX; static final int MAX_STREAM_NUMBER; final static int TYPE_BINARY; final static int TYPE_BOOLEAN; final static int TYPE_DWORD; final static int TYPE_GUID; final static int TYPE_QWORD; final static int TYPE_STRING; final static int TYPE_WORD; }