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


Java Representation.getSize方法代码示例

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


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

示例1: getAvailableSize

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Returns the size effectively available. This returns the same value as {@link Representation#getSize()} if no
 * range is defined, otherwise it
 * returns the size of the range using {@link Range#getSize()}.
 * 
 * @param representation
 *            The representation to evaluate.
 * @return The available size.
 */
public static long getAvailableSize(Representation representation) {
    Range range = representation.getRange();
    if (range == null || !isBytesRange(range)) {
        return representation.getSize();
    } else if (range.getSize() != Range.SIZE_MAX) {
        if (representation.hasKnownSize()) {
            return Math.min(range.getIndex() + range.getSize(),
                    representation.getSize()) - range.getIndex();
        } else {
            return Representation.UNKNOWN_SIZE;
        }
    } else if (representation.hasKnownSize()) {
        if (range.getIndex() != Range.INDEX_LAST) {
            return representation.getSize() - range.getIndex();
        }

        return representation.getSize();
    }

    return Representation.UNKNOWN_SIZE;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:31,代码来源:IoUtils.java

示例2: getText

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Converts the representation to a string value. Be careful when using this
 * method as the conversion of large content to a string fully stored in
 * memory can result in OutOfMemoryErrors being thrown.
 * 
 * @param representation
 *            The representation to convert.
 * @return The representation as a string value.
 */
public static String getText(Representation representation)
        throws IOException {
    String result = null;

    if (representation.isAvailable()) {
        if (representation.getSize() == 0) {
            result = "";
        } else {
            java.io.StringWriter sw = new java.io.StringWriter();
            representation.write(sw);
            sw.flush();
            result = sw.toString();
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:27,代码来源:IoUtils.java

示例3: toObject

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Converts a Representation into a regular Java object.
 * 
 * @param <T>
 *            The expected class of the Java object.
 * @param source
 *            The source representation to convert.
 * @param target
 *            The target class of the Java object.
 * @param resource
 *            The parent resource.
 * @return The converted Java object.
 * @throws IOException
 */
public <T> T toObject(Representation source, Class<T> target,
        Resource resource) throws IOException {
    T result = null;
    boolean loggable = (resource == null) ? true : resource.isLoggable();

    if ((source != null) && source.isAvailable() && (source.getSize() != 0)) {
        ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                resource);

        if (ch != null) {
            if (loggable
                    && Context.getCurrentLogger().isDebugEnabled()) {
                Context.getCurrentLogger().debug(
                        "The following converter was selected for the "
                                + source + " representation: " + ch);
            }

            result = ch.toObject(source, target, resource);

            if (result instanceof Representation) {
                Representation resultRepresentation = (Representation) result;

                // Copy the variant metadata
                resultRepresentation.setCharacterSet(source
                        .getCharacterSet());
                resultRepresentation.setMediaType(source.getMediaType());
                resultRepresentation.getEncodings().addAll(
                        source.getEncodings());
                resultRepresentation.getLanguages().addAll(
                        source.getLanguages());
            }
        } else {
            if (loggable) {
                Context.getCurrentLogger().warn(
                        "Unable to find a converter for this representation : "
                                + source);
            }
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:57,代码来源:ConverterService.java


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