當前位置: 首頁>>代碼示例>>Java>>正文


Java DiskLruCache.Editor方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.internal.DiskLruCache.Editor方法的典型用法代碼示例。如果您正苦於以下問題:Java DiskLruCache.Editor方法的具體用法?Java DiskLruCache.Editor怎麽用?Java DiskLruCache.Editor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.internal.DiskLruCache的用法示例。


在下文中一共展示了DiskLruCache.Editor方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:23,代碼來源:HttpResponseCache.java

示例2: CacheRequestImpl

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:24,代碼來源:HttpResponseCache.java

示例3: writeTo

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
public void writeTo(DiskLruCache.Editor editor) throws IOException {
  OutputStream out = editor.newOutputStream(ENTRY_METADATA);
  Writer writer = new BufferedWriter(new OutputStreamWriter(out, UTF_8));

  writer.write(uri + '\n');
  writer.write(requestMethod + '\n');
  writer.write(Integer.toString(varyHeaders.length()) + '\n');
  for (int i = 0; i < varyHeaders.length(); i++) {
    writer.write(varyHeaders.getFieldName(i) + ": " + varyHeaders.getValue(i) + '\n');
  }

  writer.write(responseHeaders.getStatusLine() + '\n');
  writer.write(Integer.toString(responseHeaders.length()) + '\n');
  for (int i = 0; i < responseHeaders.length(); i++) {
    writer.write(responseHeaders.getFieldName(i) + ": " + responseHeaders.getValue(i) + '\n');
  }

  if (isHttps()) {
    writer.write('\n');
    writer.write(cipherSuite + '\n');
    writeCertArray(writer, peerCertificates);
    writeCertArray(writer, localCertificates);
  }
  writer.close();
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:26,代碼來源:HttpResponseCache.java

示例4: abortQuietly

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
private void abortQuietly(DiskLruCache.Editor editor) {
  // Give up because the cache cannot be written.
  try {
    if (editor != null) {
      editor.abort();
    }
  } catch (IOException ignored) {
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:10,代碼來源:HttpResponseCache.java

示例5: abortQuietly

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
private void abortQuietly(DiskLruCache.Editor editor) {
    // Give up because the cache cannot be written.
    try {
        if (editor != null) {
            editor.abort();
        }
    } catch (IOException ignored) {
    }
}
 
開發者ID:goodev,項目名稱:android-discourse,代碼行數:10,代碼來源:HttpResponseCache.java

示例6: put

import com.squareup.okhttp.internal.DiskLruCache; //導入方法依賴的package包/類
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();

  if (maybeRemove(requestMethod, uri)) {
    return null;
  }
  if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(uriToKey(uri));
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:46,代碼來源:HttpResponseCache.java


注:本文中的com.squareup.okhttp.internal.DiskLruCache.Editor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。