|
楼主 |
发表于 2017-1-12 15:59:02
|
显示全部楼层
3、调用到的方法(上面那层楼太长了,放不下了拆开放。。。)
- private String getEcoding(byte[] dataOrigin) {
- // TODO Auto-generated method stub
- String reqcontent = new String(dataOrigin);
-
- return StringUtils.substringBefore(reqcontent.split("charset=ISO-8859-1\r\n")[1], "\r\n\r\n");
- }
- //java 合并3个byte数组
- public byte[] byteMerger(byte[] byte_1, byte[] byte_2,byte[] byte_3) throws UnsupportedEncodingException{
- byte[] byte_4 = new byte[byte_1.length+byte_2.length+byte_3.length];
- System.arraycopy(byte_1, 0, byte_4, 0, byte_1.length); //原数组、原数组起始位置、目标数组、目标数组起始位置、插入数组的长度
- System.arraycopy(byte_2, 0, byte_4, byte_1.length, byte_2.length);
- System.arraycopy(byte_3, 0, byte_4, byte_1.length+byte_2.length, byte_3.length);
- // String finalb = new String(byte_1)+"\r\n"+new String(byte_2,"utf-8")+"\r\n"+new String(byte_3);
- // byte_4 = finalb.getBytes();
- return byte_4;
- }
-
- private byte[] getBytes(String filePath){
- byte[] buffer1 = null;
- try {
- File file = new File(filePath);
- FileInputStream fis = new FileInputStream(file);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- byte[] b = new byte[1024];
- int n;
- while ((n = fis.read(b)) != -1) {
- bos.write(b, 0, n);
- }
- fis.close();
- bos.close();
- buffer1 = bos.toByteArray();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return buffer1;
- }
- private static int byteIndexOf(byte[] b, String s, int start) {
- return byteIndexOf(b, s.getBytes(), start);
- }
- private static int byteIndexOf(byte[] b, byte[] s, int start) {
- int i;
- if (s.length == 0) {
- return 0;
- }
- int max = b.length - s.length;
- if (max < 0) {
- return -1;
- }
- if (start > max) {
- return -1;
- }
- if (start < 0) {
- start = 0;
- }
- // 在b中找到s的第一个元素
- search: for (i = start; i <= max; i++) {
- if (b[i] == s[0]) {
- // 找到了s中的第一个元素后,比较剩余的部分是否相等
- int k = 1;
- while (k < s.length) {
- if (b[k + i] != s[k]) {
- continue search;
- }
- k++;
- }
- return i;
- }
- }
- return -1;
- }
- private static byte[] subBytes(byte[] b, int from, int end) {
- byte[] result = new byte[end - from];
- System.arraycopy(b, from, result, 0, end - from);
- return result;
- }
- private static String subBytesString(byte[] b, int from, int end) {
- return new String(subBytes(b, from, end));
- }
- }
- class BufferedServletInputStream extends ServletInputStream {
- private ByteArrayInputStream inputStream;
- public BufferedServletInputStream(byte[] buffer) {
- this.inputStream = new ByteArrayInputStream( buffer );
- }
- @Override
- public int available() throws IOException {
- return inputStream.available();
- }
- @Override
- public int read() throws IOException {
- return inputStream.read();
- }
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- return inputStream.read( b, off, len );
- }
- }
复制代码
|
|