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

📄 staticmethod.java

📁 java 小型系统连接池参照适用于中小型网站
💻 JAVA
字号:
package ntis.com.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletInputStream;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Hashtable;
import java.math.*;

public class StaticMethod {
  public StaticMethod() {}

  public static byte[] extractFileFromRequest(HttpServletRequest request, String paramName) throws Exception {
    boolean _result  = false;
    byte    _bBuff[]    = new byte[request.getContentLength()];
    byte    _fileBuff[] = new byte[request.getContentLength()];
    int     _len = 0;
    int     _contentLength = 0;
    int     _fileSize      = 0;

    ServletInputStream _in  = request.getInputStream();

    _len = _in.readLine(_bBuff, 0, _bBuff.length);

    while(_len != -1) {
      _contentLength += _len;

      StringTokenizer _st = new StringTokenizer(new String(_bBuff, 0, _len), ";");

      if(_st.countTokens() == 0) {
        _len = _in.readLine(_bBuff, 0, _bBuff.length);
        continue;
      }

      if(!_st.nextToken().equals("Content-Disposition: form-data")) {
        _len = _in.readLine(_bBuff, 0, _bBuff.length);
        continue;
      }

      String _valueName = _st.nextToken();

      if(_valueName.startsWith(" name=\"" + paramName + "\"")) {
        _len = _in.readLine(_bBuff, 0, _bBuff.length);
        _contentLength += _len; _len = _in.readLine(_bBuff, 0, _bBuff.length);
        _contentLength += _len; _len = _in.readLine(_bBuff, 0, _bBuff.length);

        while(_len != -1) {
          _contentLength += _len;
          if(new String(_bBuff, 0, _len).startsWith("--------------------")) {break;}

          for(int i = 0; i < _len; i++, _fileSize++) {
            _fileBuff[_fileSize] = _bBuff[i];
          }

          _len = _in.readLine(_bBuff, 0, _bBuff.length);
        }
      } // if(_valueName.equals(" name=\"uploadFileName\""))

      _len = _in.readLine(_bBuff, 0, _bBuff.length);
    } // while(_len != -1)

    if(request.getContentLength() == _contentLength) {
      _bBuff = new byte[_fileSize];

      for(int i = 0; i < _fileSize; i++) {
        _bBuff[i] = _fileBuff[i];
      }
    }
    else {
      _bBuff = null;
    }

    return _bBuff;
  }
  /**<p>
  *嬥妟偺偺巐幪屲擖傪峴偆
  *</p>
  *@param  price    嬥妟
  *@param  digit    巐幪屲擖偡傞懳徾寘偺埵抲
  *@throws Exception 壗傜偐偺椺奜偑敪惗偟偨応崌丅
  */
  public static BigDecimal roundOff( BigDecimal price , int digit )throws Exception{
    price = price.movePointLeft(digit).setScale(0,BigDecimal.ROUND_HALF_UP);
    price = price.movePointRight(digit);
    return( price );

  }
}

⌨️ 快捷键说明

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