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


Java Util.closeQuietly方法代码示例

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


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

示例1: create

import okhttp3.internal.Util; //导入方法依赖的package包/类
/** Returns a new request body that transmits the content of {@code file}. */
public static RequestBody create(final MediaType contentType, final File file) {
  if (file == null) throw new NullPointerException("content == null");

  return new RequestBody() {
    @Override public MediaType contentType() {
      return contentType;
    }

    @Override public long contentLength() {
      return file.length();
    }

    @Override public void writeTo(BufferedSink sink) throws IOException {
      Source source = null;
      try {
        source = Okio.source(file);
        sink.writeAll(source);
      } finally {
        Util.closeQuietly(source);
      }
    }
  };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RequestBody.java

示例2: execute

import okhttp3.internal.Util; //导入方法依赖的package包/类
@Override protected void execute() {
  ErrorCode connectionErrorCode = ErrorCode.INTERNAL_ERROR;
  ErrorCode streamErrorCode = ErrorCode.INTERNAL_ERROR;
  try {
    reader.readConnectionPreface(this);
    while (reader.nextFrame(false, this)) {
    }
    connectionErrorCode = ErrorCode.NO_ERROR;
    streamErrorCode = ErrorCode.CANCEL;
  } catch (IOException e) {
    connectionErrorCode = ErrorCode.PROTOCOL_ERROR;
    streamErrorCode = ErrorCode.PROTOCOL_ERROR;
  } finally {
    try {
      close(connectionErrorCode, streamErrorCode);
    } catch (IOException ignored) {
    }
    Util.closeQuietly(reader);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:Http2Connection.java

示例3: serveFile

import okhttp3.internal.Util; //导入方法依赖的package包/类
private void serveFile(Http2Stream stream, File file) throws IOException {
  List<Header> responseHeaders = Arrays.asList(
      new Header(":status", "200"),
      new Header(":version", "HTTP/1.1"),
      new Header("content-type", contentType(file))
  );
  stream.sendResponseHeaders(responseHeaders, true);
  Source source = Okio.source(file);
  try {
    BufferedSink out = Okio.buffer(stream.getSink());
    out.writeAll(source);
    out.close();
  } finally {
    Util.closeQuietly(source);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:Http2Server.java

示例4: create

import okhttp3.internal.Util; //导入方法依赖的package包/类
/** Returns a new request body that transmits the content of {@code file}. */
public static RequestBody create(final @Nullable MediaType contentType, final File file) {
  if (file == null) throw new NullPointerException("content == null");

  return new RequestBody() {
    @Override public @Nullable MediaType contentType() {
      return contentType;
    }

    @Override public long contentLength() {
      return file.length();
    }

    @Override public void writeTo(BufferedSink sink) throws IOException {
      Source source = null;
      try {
        source = Okio.source(file);
        sink.writeAll(source);
      } finally {
        Util.closeQuietly(source);
      }
    }
  };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RequestBody.java

示例5: abort

import okhttp3.internal.Util; //导入方法依赖的package包/类
@Override public void abort() {
  synchronized (Cache.this) {
    if (done) {
      return;
    }
    done = true;
    writeAbortCount++;
  }
  Util.closeQuietly(cacheOut);
  try {
    editor.abort();
  } catch (IOException ignored) {
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:Cache.java

示例6: snapshot

import okhttp3.internal.Util; //导入方法依赖的package包/类
/**
 * Returns a snapshot of this entry. This opens all streams eagerly to guarantee that we see a
 * single published snapshot. If we opened streams lazily then the streams could come from
 * different edits.
 */
Snapshot snapshot() {
  if (!Thread.holdsLock(DiskLruCache.this)) throw new AssertionError();

  Source[] sources = new Source[valueCount];
  long[] lengths = this.lengths.clone(); // Defensive copy since these can be zeroed out.
  try {
    for (int i = 0; i < valueCount; i++) {
      sources[i] = fileSystem.source(cleanFiles[i]);
    }
    return new Snapshot(key, sequenceNumber, sources, lengths);
  } catch (FileNotFoundException e) {
    // A file must have been deleted manually!
    for (int i = 0; i < valueCount; i++) {
      if (sources[i] != null) {
        Util.closeQuietly(sources[i]);
      } else {
        break;
      }
    }
    // Since the entry is no longer valid, remove it so the metadata is accurate (i.e. the cache
    // size.)
    try {
      removeEntry(this);
    } catch (IOException ignored) {
    }
    return null;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:DiskLruCache.java

示例7: create

import okhttp3.internal.Util; //导入方法依赖的package包/类
protected RequestBody create(final MediaType mediaType, final InputStream inputStream) {
    return new RequestBody() {
        @Override
        public MediaType contentType() {
            return mediaType;
        }

        @Override
        public long contentLength() {
            try {
                return inputStream.available();
            } catch (IOException e) {
                return 0;
            }
        }

        @Override
        public void writeTo(@NonNull BufferedSink sink) throws IOException {
            Source source = null;
            try {
                source = Okio.source(inputStream);
                sink.writeAll(source);
            } finally {
                Util.closeQuietly(source);
            }
        }
    };
}
 
开发者ID:qiaodashaoye,项目名称:SuperHttp,代码行数:29,代码来源:UploadRequest.java

示例8: create

import okhttp3.internal.Util; //导入方法依赖的package包/类
public static RequestBody create(final MediaType mediaType, final InputStream inputStream) {
    return new RequestBody() {
        @Override
        public MediaType contentType() {
            return mediaType;
        }

        @Override
        public long contentLength() {
            try {
                return inputStream.available();
            } catch (IOException e) {
                return 0;
            }
        }

        @Override
        public void writeTo(BufferedSink sink) throws IOException {
            Source source = null;
            try {
                source = Okio.source(inputStream);
                sink.writeAll(source);
            } finally {
                Util.closeQuietly(source);
            }
        }
    };
}
 
开发者ID:CatalystCode,项目名称:Custom-Vison-Service,代码行数:29,代码来源:HttpHelper.java

示例9: parse

import okhttp3.internal.Util; //导入方法依赖的package包/类
public static <T> Observable<T> parse(Response response, Class<T> clazz) {
    try {
        final ResponseBody responseBody = response.body();
        Reader reader = responseBody.charStream();

        try {
            if (!response.isSuccessful()) {
                ErrorResponseDto errorResponseDto = Clients
                        .defaultObjectMapper
                        .fromJson(reader, ErrorResponseDto.class);

                return Observable.error(new AccessApiException(errorResponseDto, null));
            }

            T parsedBody = Clients
                    .defaultObjectMapper
                    .fromJson(reader, clazz);

            return Observable.just(parsedBody);
        } finally {
            Util.closeQuietly(reader);
        }
    } catch (Exception e) {
        return Observable.error(e);
    } finally {
        Util.closeQuietly(response);
    }
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:29,代码来源:ResponseHelper.java

示例10: writeTo

import okhttp3.internal.Util; //导入方法依赖的package包/类
@Override
public void writeTo(BufferedSink sink) throws IOException {
    Source source = null;
    try {
        source = Okio.source(inputStream);
        sink.writeAll(source);
    } finally {
        Util.closeQuietly(source);
    }
}
 
开发者ID:domoinc,项目名称:domo-java-sdk,代码行数:11,代码来源:InputStreamRequestBody.java

示例11: readJournal

import okhttp3.internal.Util; //导入方法依赖的package包/类
private void readJournal() throws IOException {
  BufferedSource source = Okio.buffer(fileSystem.source(journalFile));
  try {
    String magic = source.readUtf8LineStrict();
    String version = source.readUtf8LineStrict();
    String appVersionString = source.readUtf8LineStrict();
    String valueCountString = source.readUtf8LineStrict();
    String blank = source.readUtf8LineStrict();
    if (!MAGIC.equals(magic)
        || !VERSION_1.equals(version)
        || !Integer.toString(appVersion).equals(appVersionString)
        || !Integer.toString(valueCount).equals(valueCountString)
        || !"".equals(blank)) {
      throw new IOException("unexpected journal header: [" + magic + ", " + version + ", "
          + valueCountString + ", " + blank + "]");
    }

    int lineCount = 0;
    while (true) {
      try {
        readJournalLine(source.readUtf8LineStrict());
        lineCount++;
      } catch (EOFException endOfJournal) {
        break;
      }
    }
    redundantOpCount = lineCount - lruEntries.size();

    // If we ended on a truncated line, rebuild the journal before appending to it.
    if (!source.exhausted()) {
      rebuildJournal();
    } else {
      journalWriter = newJournalWriter();
    }
  } finally {
    Util.closeQuietly(source);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:DiskLruCache.java

示例12: close

import okhttp3.internal.Util; //导入方法依赖的package包/类
@Override public void close() {
  Util.closeQuietly(source());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:ResponseBody.java

示例13: close

import okhttp3.internal.Util; //导入方法依赖的package包/类
public void close() {
  for (Source in : sources) {
    Util.closeQuietly(in);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:DiskLruCache.java

示例14: tearDown

import okhttp3.internal.Util; //导入方法依赖的package包/类
@After public void tearDown() throws Exception {
  cache.delete();
  Util.closeQuietly(nullServer);
  logger.removeHandler(logHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:CallTest.java

示例15: close

import okhttp3.internal.Util; //导入方法依赖的package包/类
public void close() {
  for (InputStream in : ins) {
    Util.closeQuietly(in);
  }
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:6,代码来源:DiskLruCache.java


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