java的http协议文件上传 (三)

MultipartRequest.java文件下半部内容如下:
 
 public String getAuthType() {
  return req_.getAuthType();
 }
 public Cookie[] getCookies() {
  return req_.getCookies();
 }
 public long getDateHeader(String arg0) {
  return req_.getDateHeader(arg0);
 }
 public String getHeader(String arg0) {
  return req_.getHeader(arg0);
 }
 public Enumeration<Object> getHeaders(String arg0) {
  return null;
 }
 public Enumeration<Object> getHeaderNames() {
  return null;
 }
 public int getIntHeader(String arg0) {
  return 0;
 }
 public String getMethod() {
  return null;
 }
 public String getPathInfo() {
  return null;
 }
 public String getPathTranslated() {
  return null;
 }
 public String getContextPath() {
  return null;
 }
 public String getQueryString() {
  return null;
 }
 public String getRemoteUser() {
  return req_.getRemoteUser();
 }
 public boolean isUserInRole(String arg0) {
  return req_.isUserInRole(arg0);
 }
 public Principal getUserPrincipal() {
  return req_.getUserPrincipal();
 }
 public String getRequestedSessionId() {
  return req_.getRequestedSessionId();
 }
 public String getRequestURI() {
  return req_.getRequestURI();
 }
 public String getServletPath() {
  return req_.getServletPath();
 }
 public HttpSession getSession(boolean arg0) {
  return req_.getSession(arg0);
 }
 public HttpSession getSession() {
  return req_.getSession();
 }
 public boolean isRequestedSessionIdValid() {
  return req_.isRequestedSessionIdValid();
 }
 public boolean isRequestedSessionIdFromCookie() {
  return req_.isRequestedSessionIdFromCookie();
 }
 public boolean isRequestedSessionIdFromURL() {
  return req_.isRequestedSessionIdFromURL();
 }
 public Object getAttribute(String arg0) {
  return req_.getAttribute(arg0);
 }
 public Enumeration getAttributeNames() {
  return req_.getAttributeNames();
 }
 public String getCharacterEncoding() {
  return req_.getCharacterEncoding();
 }
 public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException {
 }
 public int getContentLength() {
  return req_.getContentLength();
 }
 public String getContentType() {
  return req_.getContentType();
 }
 public ServletInputStream getInputStream() throws IOException {
  return req_.getInputStream();
 }
  public String getParameter(String arg0) {
  try {
   ArrayList values = (ArrayList) parameters_.get(arg0);
   if (values == null || values.size() == 0) {
    return req_.getParameter(arg0);
   }
   String value = (String) values.get(values.size() - 1);
   return value;
  } catch (Exception e) {
   return null;
  }
 }
 public Enumeration getParameterNames() {
  return req_.getParameterNames();
 }
 public String[] getParameterValues(String arg0) {
  return req_.getParameterValues(arg0);
 }
 public String getProtocol() {
  return req_.getProtocol();
 }
 public String getScheme() {
  return req_.getScheme();
 }
 public String getServerName() {
  return req_.getServerName();
 }
 public int getServerPort() {
  return req_.getServerPort();
 }
 public BufferedReader getReader() throws IOException {
  return req_.getReader();
 }
 public String getRemoteAddr() {
  return req_.getRemoteAddr();
 }
 public String getRemoteHost() {
  return req_.getRemoteHost();
 }
 public void setAttribute(String arg0, Object arg1) {
 }
 public void removeAttribute(String arg0) {
 }
 public Locale getLocale() {
  return req_.getLocale();
 }
 public Enumeration getLocales() {
  return req_.getLocales();
 }
 public boolean isSecure() {
  return false;
 }
 public RequestDispatcher getRequestDispatcher(String arg0) {
  return req_.getRequestDispatcher(arg0);
 }
 public void deleteTemporaryFile() {
  Set<File> files = exactFileNameTable_.keySet();
  Iterator<File> iteratorOfFiles = files.iterator();
  while (iteratorOfFiles.hasNext()) {
   File fileToDel = (File) iteratorOfFiles.next();
   if (fileToDel != null) {
    fileToDel.delete();
   }
  }
 }
 public String getFileName(File file) throws UnsupportedEncodingException {
  return (String)exactFileNameTable_.get(file);
 }
    public StringBuffer getRequestURL() {
        return req_.getRequestURL();
    }
    public Map<?, ?> getParameterMap() {
        return req_.getParameterMap();
    }
 public boolean isRequestedSessionIdFromUrl() {
  return false;
 }
 public String getRealPath(String arg0) {
  return null;
 }
 public int getRemotePort() {
  return req_.getRemotePort();
 }
 public String getLocalName() {
  return req_.getLocalName();
 }
 public String getLocalAddr() {
  return req_.getLocalAddr();
 }
 public int getLocalPort() {
  return req_.getLocalPort();
 }
}
class MultipartInputStreamHandler {
    ServletInputStream in;
    int totalExpected;
    int totalRead = 0;
    byte[] buf = new byte[8 * 1024];
    MultipartInputStreamHandler(ServletInputStream in,
                                       int totalExpected) {
        this.in = in;
        this.totalExpected = totalExpected;
    }
    String readLine() throws IOException {
        StringBuffer sbuf = new StringBuffer();
        int result;
        do {
            result = this.readLine(buf, 0, buf.length);
            if (result != -1) {
                sbuf.append(new String(buf, 0, result, "GB2312"));
            }
        } while (result == buf.length);
        if (sbuf.length() == 0) {
            return null;
        }
        sbuf.setLength(sbuf.length() - 2);
        return sbuf.toString();
    }
    int readLine(byte b[], int off, int len) throws IOException {
        if (totalRead >= totalExpected) {
            return -1;
        }
        else {
            if (len > (totalExpected - totalRead)) {
                len = totalExpected - totalRead;
            }
            int result = in.readLine(b, off, len);
            if (result > 0) {
                totalRead += result;
            }
            return result;
        }
    }
}
class UploadedFile {
 private File temporaryFile_;
 private String type_;
 UploadedFile(File temporaryFile, String type) {
  temporaryFile_ = temporaryFile;
  type_ = type;
 }
 String getContentType() {
  return type_;
 }
 File getFile() {
  return temporaryFile_;
 }
}
class MacBinaryDecoderOutputStream extends FilterOutputStream {
    private int bytesFiltered_ = 0;
    private int dataForkLength_ = 0;
    MacBinaryDecoderOutputStream(OutputStream out) {
        super(out);
    }
    public void write(int b) throws IOException {
        if (bytesFiltered_ <= 86 && bytesFiltered_ >= 83) {
            int leftShift = (86 - bytesFiltered_) * 8;
            dataForkLength_ = dataForkLength_ | (b & 0xff) << leftShift;
        }
        else if (bytesFiltered_ < (128 + dataForkLength_) && bytesFiltered_ >= 128) {
            out.write(b);
        }
        bytesFiltered_++;
    }
    public void write(byte[] b, int off, int len) throws IOException {
        if (bytesFiltered_ >= (128 + dataForkLength_)) {
            bytesFiltered_ += len;
        }
        else if (bytesFiltered_ >= 128 &&
                 (bytesFiltered_ + len) <= (128 + dataForkLength_)) {
            out.write(b, off, len);
            bytesFiltered_ += len;
        }
        else {
            for (int i = 0 ; i < len ; i++) {
                write(b[off + i]);
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值