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


Java Preconditions类代码示例

本文整理汇总了Java中com.google.inject.internal.Preconditions的典型用法代码示例。如果您正苦于以下问题:Java Preconditions类的具体用法?Java Preconditions怎么用?Java Preconditions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: makeResponse

import com.google.inject.internal.Preconditions; //导入依赖的package包/类
/**
 * @param response The response to parse
 * @return A HttpResponse object made by consuming the response of the
 *         given HttpMethod.
 * @throws IOException when problems occur processing the body content
 */
@SuppressWarnings("unchecked")
private HttpResponse makeResponse(Response response) throws IOException {
    HttpResponseBuilder builder = new HttpResponseBuilder();

    Series<Parameter> headers = (Series<Parameter>) response.getAttributes().get("org.restlet.http.headers");
    if (headers != null) {
        for (Parameter param : headers) {
            if (param.getName() != null) {
                builder.addHeader(param.getName(), param.getValue());
            }
        }
    }

    Representation entity = Preconditions.checkNotNull(response.getEntity());

    if (maxObjSize > 0 && entity != null && entity.getSize() > maxObjSize) {
        return HttpResponse.badrequest("Exceeded maximum number of bytes - " + maxObjSize);
    }

    return builder.setHttpStatusCode(response.getStatus().getCode()).setResponse(toByteArraySafe(entity)).create();
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:28,代码来源:ClientHttpFetcher.java

示例2: AbstractDesignFileHandler

import com.google.inject.internal.Preconditions; //导入依赖的package包/类
/**
 * @param sessionTransactionManager the SessionTransactionManager to use
 * @param dataStorageFacade data storage facade to use
 * @param arrayDao the ArrayDao to use
 * @param searchDao the SearchDao to use
 */
protected AbstractDesignFileHandler(SessionTransactionManager sessionTransactionManager,
        DataStorageFacade dataStorageFacade, ArrayDao arrayDao, SearchDao searchDao) {
    Preconditions.checkNotNull(sessionTransactionManager);
    Preconditions.checkNotNull(dataStorageFacade);
    Preconditions.checkNotNull(searchDao);
    Preconditions.checkNotNull(arrayDao);

    this.sessionTransactionManager = sessionTransactionManager;
    this.dataStorageFacade = dataStorageFacade;
    this.searchDao = searchDao;
    this.arrayDao = arrayDao;
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:19,代码来源:AbstractDesignFileHandler.java

示例3: toByteArraySafe

import com.google.inject.internal.Preconditions; //导入依赖的package包/类
/**
 * This method is Safe replica version of org.apache.http.util.EntityUtils.toByteArray.
 * The try block embedding 'instream.read' has a corresponding catch block for 'EOFException'
 * (that's Ignored) and all other IOExceptions are let pass.
 *
 * @param entity
 * @return byte array containing the entity content. May be empty/null.
 * @throws IOException if an error occurs reading the input stream
 */
public byte[] toByteArraySafe(final Representation entity) throws IOException {
    if (entity == null) {
        return null;
    }

    InputStream instream = entity.getStream();
    if (instream == null) {
        return new byte[] {};
    }
    Preconditions.checkArgument(entity.getSize() < Integer.MAX_VALUE, "HTTP entity too large to be buffered in memory");

    // The raw data stream (inside JDK) is read in a buffer of size '512'. The original code
    // org.apache.http.util.EntityUtils.toByteArray reads the unzipped data in a buffer of
    // 4096 byte. For any data stream that has a compression ratio lesser than 1/8, this may
    // result in the buffer/array overflow. Increasing the buffer size to '16384'. It's highly
    // unlikely to get data compression ratios lesser than 1/32 (3%).
    final int bufferLength = 16384;
    int i = (int) entity.getSize();
    if (i < 0) {
        i = bufferLength;
    }
    ByteArrayBuffer buffer = new ByteArrayBuffer(i);
    try {
        byte[] tmp = new byte[bufferLength];
        int l;
        while ((l = instream.read(tmp)) != -1) {
            buffer.append(tmp, 0, l);
        }
    } catch (EOFException eofe) {
        /**
         * Ref: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4040920
         * Due to a bug in JDK ZLIB (InflaterInputStream), unexpected EOF error can occur.
         * In such cases, even if the input stream is finished reading, the
         * 'Inflater.finished()' call erroneously returns 'false' and
         * 'java.util.zip.InflaterInputStream.fill' throws the 'EOFException'.
         * So for such case, ignore the Exception in case Exception Cause is
         * 'Unexpected end of ZLIB input stream'.
         *
         * Also, ignore this exception in case the exception has no message
         * body as this is the case where {@link GZIPInputStream#readUByte}
         * throws EOFException with empty message. A bug has been filed with Sun
         * and will be mentioned here once it is accepted.
         */
        if (instream.available() == 0 && (eofe.getMessage() == null || eofe.getMessage().equals("Unexpected end of ZLIB input stream"))) {
            LOG.log(Level.FINE, "EOFException: ", eofe);
        } else {
            throw eofe;
        }
    } finally {
        instream.close();
    }
    return buffer.toByteArray();
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:63,代码来源:ClientHttpFetcher.java

示例4: setConnectionTimeoutMs

import com.google.inject.internal.Preconditions; //导入依赖的package包/类
/**
 * Change the global connection timeout for all fetchs.
 *
 * @param connectionTimeoutMs new connection timeout in milliseconds
 */
@Inject(optional = true)
public void setConnectionTimeoutMs(@Named("shindig.http.client.connection-timeout-ms") int connectionTimeoutMs) {
  Preconditions.checkArgument(connectionTimeoutMs > 0, "connection-timeout-ms must be greater than 0");
  this.connectionTimeoutMs = connectionTimeoutMs;
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:11,代码来源:BasicHttpFetcher.java


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