⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cacheingoutputstream.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 */
package com.sslexplorer.replacementproxy;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


public class CacheingOutputStream extends OutputStream implements Serializable {
  transient OutputStream out;
  private byte buf[];
  private List headers;
  private int idx;
  private String contentType;
  private Date cachedDate;

  public CacheingOutputStream(OutputStream out, int size, List headers, String contentType) {
    super();
    this.out = out;
    cachedDate = new Date();
    this.contentType = contentType;
    this.headers = headers;
    buf = new byte[size];
  }
  
  public Date getCachedDate() {
  	return cachedDate;
  }

  public byte[] getBytes() {
    byte b[] = new byte[idx];
    System.arraycopy(buf, 0, b, 0, idx);
    return b;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.io.Closeable#close()
   */
  public void close() throws IOException {
    out.close();
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.io.OutputStream#write(byte[], int, int)
   */
  public synchronized void write(byte[] b, int off, int len) throws IOException {
    out.write(b, off, len);
    if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
      throw new IndexOutOfBoundsException();
    } else if (len == 0) {
      return;
    }
    int nidx = idx + len;
    if (nidx > buf.length) {
      byte newbuf[] = new byte[Math.max(buf.length << 1, nidx)];
      System.arraycopy(buf, 0, newbuf, 0, idx);
      buf = newbuf;
    }
    System.arraycopy(b, off, buf, idx, len);
    idx = nidx;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.io.OutputStream#write(int)
   */
  public synchronized void write(int b) throws IOException {
    out.write(b);
    int nidx = idx + 1;
    if (nidx > buf.length) {
      byte nbuf[] = new byte[Math.max(buf.length << 1, nidx)];
      System.arraycopy(buf, 0, nbuf, 0, idx);
      buf = nbuf;
    }
    buf[idx] = (byte) b;
    idx = nidx;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.io.Flushable#flush()
   */
  public void flush() throws IOException {
    out.flush();
  }
  /**
   * @return Returns the contentType.
   */
  public String getContentType() {
    return contentType;
  }
  /**
   * @param contentType The contentType to set.
   */
  public void setContentType(String contentType) {
    this.contentType = contentType;
  }
  /**
   * @return Returns the headers.
   */
  public List getHeaders() {
    return headers;
  }
  /**
   * @param headers The headers to set.
   */
  public void setHeaders(List headers) {
    this.headers = headers;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -