当前位置: 首页>>代码示例>>Java>>正文


Java Directory.setStringArray方法代码示例

本文整理汇总了Java中com.drew.metadata.Directory.setStringArray方法的典型用法代码示例。如果您正苦于以下问题:Java Directory.setStringArray方法的具体用法?Java Directory.setStringArray怎么用?Java Directory.setStringArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.drew.metadata.Directory的用法示例。


在下文中一共展示了Directory.setStringArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processTag

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void processTag(@NotNull SequentialReader reader, @NotNull Directory directory, int directoryType, int tagType, int tagByteCount) throws IOException
{
    int tagIdentifier = tagType | (directoryType << 8);

    String string = null;

    switch (tagIdentifier) {
        case IptcDirectory.TAG_APPLICATION_RECORD_VERSION:
            // short
            int shortValue = reader.getUInt16();
            reader.skip(tagByteCount - 2);
            directory.setInt(tagIdentifier, shortValue);
            return;
        case IptcDirectory.TAG_URGENCY:
            // byte
            directory.setInt(tagIdentifier, reader.getUInt8());
            reader.skip(tagByteCount - 1);
            return;
        case IptcDirectory.TAG_RELEASE_DATE:
        case IptcDirectory.TAG_DATE_CREATED:
            // Date object
            if (tagByteCount >= 8) {
                string = reader.getString(tagByteCount);
                try {
                    int year = Integer.parseInt(string.substring(0, 4));
                    int month = Integer.parseInt(string.substring(4, 6)) - 1;
                    int day = Integer.parseInt(string.substring(6, 8));
                    Date date = new java.util.GregorianCalendar(year, month, day).getTime();
                    directory.setDate(tagIdentifier, date);
                    return;
                } catch (NumberFormatException e) {
                    // fall through and we'll process the 'string' value below
                }
            } else {
                reader.skip(tagByteCount);
            }
        case IptcDirectory.TAG_RELEASE_TIME:
        case IptcDirectory.TAG_TIME_CREATED:
            // time...
        default:
            // fall through
    }

    // If we haven't returned yet, treat it as a string
    // NOTE that there's a chance we've already loaded the value as a string above, but failed to parse the value
    if (string == null) {
        string = reader.getString(tagByteCount, System.getProperty("file.encoding")); // "ISO-8859-1"
    }

    if (directory.containsTag(tagIdentifier)) {
        // this fancy string[] business avoids using an ArrayList for performance reasons
        String[] oldStrings = directory.getStringArray(tagIdentifier);
        String[] newStrings;
        if (oldStrings == null) {
            newStrings = new String[1];
        } else {
            newStrings = new String[oldStrings.length + 1];
            System.arraycopy(oldStrings, 0, newStrings, 0, oldStrings.length);
        }
        newStrings[newStrings.length - 1] = string;
        directory.setStringArray(tagIdentifier, newStrings);
    } else {
        directory.setString(tagIdentifier, string);
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:66,代码来源:IptcReader.java

示例2: processTag

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void processTag(@NotNull BufferReader reader, @NotNull Directory directory, int directoryType, int tagType, int offset, int tagByteCount) throws BufferBoundsException
{
    int tagIdentifier = tagType | (directoryType << 8);

    switch (tagIdentifier) {
        case IptcDirectory.TAG_APPLICATION_RECORD_VERSION:
            // short
            int shortValue = reader.getUInt16(offset);
            directory.setInt(tagIdentifier, shortValue);
            return;
        case IptcDirectory.TAG_URGENCY:
            // byte
            directory.setInt(tagIdentifier, reader.getUInt8(offset));
            return;
        case IptcDirectory.TAG_RELEASE_DATE:
        case IptcDirectory.TAG_DATE_CREATED:
            // Date object
            if (tagByteCount >= 8) {
                String dateStr = reader.getString(offset, tagByteCount);
                try {
                    int year = Integer.parseInt(dateStr.substring(0, 4));
                    int month = Integer.parseInt(dateStr.substring(4, 6)) - 1;
                    int day = Integer.parseInt(dateStr.substring(6, 8));
                    Date date = new java.util.GregorianCalendar(year, month, day).getTime();
                    directory.setDate(tagIdentifier, date);
                    return;
                } catch (NumberFormatException e) {
                    // fall through and we'll store whatever was there as a String
                }
            }
        case IptcDirectory.TAG_RELEASE_TIME:
        case IptcDirectory.TAG_TIME_CREATED:
            // time...
        default:
            // fall through
    }

    // If we haven't returned yet, treat it as a string
    String str;
    if (tagByteCount < 1) {
        str = "";
    } else {
        str = reader.getString(offset, tagByteCount, System.getProperty("file.encoding")); // "ISO-8859-1"
    }

    if (directory.containsTag(tagIdentifier)) {
        // this fancy string[] business avoids using an ArrayList for performance reasons
        String[] oldStrings = directory.getStringArray(tagIdentifier);
        String[] newStrings;
        if (oldStrings == null) {
            newStrings = new String[1];
        } else {
            newStrings = new String[oldStrings.length + 1];
            System.arraycopy(oldStrings, 0, newStrings, 0, oldStrings.length);
        }
        newStrings[newStrings.length - 1] = str;
        directory.setStringArray(tagIdentifier, newStrings);
    } else {
        directory.setString(tagIdentifier, str);
    }
}
 
开发者ID:mxbossard,项目名称:metadata-extractor-osgi,代码行数:62,代码来源:IptcReader.java


注:本文中的com.drew.metadata.Directory.setStringArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。