获取需要发送的报文长度

@param bean
@param charset
@return
@throws NoSuchMethodException
@throws InvocationTargetException
@throws IllegalAccessException
967058
public int getFieldsSendTotalByteSize(Object bean, Charset charset) {
        if (!hasDynamicField()) {
            return fieldsTotalSize;
        } else {
            return getDynamicTotalFieldSize(bean, charset);
        }
    }
1282900
public static String asString(byte[] bytes, Charset charset)
    {
        if (bytes == null)
        {
            return null;
        }

        if (charset == null)
        {
            throw new IllegalArgumentException("Cannot get bytes without a Charset");
        }

        try
        {
            return new String(bytes, charset.name());
        }
        catch (UnsupportedEncodingException e)
        {
            throw new IllegalStateException(charset.name() + " must be present", e);
        }
    }
483180
public static String read(InputStream in, String charset) throws IOException {
        if (in == null) {
            throw new IllegalArgumentException("input stream cannot be null");
        }
        InputStreamReader reader = null;
        try {
            reader = new InputStreamReader(in, charset);
            char[] buffer = new char[1024];
            StringBuilder sb = new StringBuilder();
            int len;
            while ((len = reader.read(buffer)) != -1) {
                sb.append(buffer, 0, len);
            }
            return sb.toString();
        } finally {
            closeQuietly(reader);
        }
    }
835736
@Override
    @SuppressWarnings("unchecked")
    public P get(Bean bean) {
        try {
            return (P) getter.apply(bean);
        } catch (RuntimeException | Error ex) {
            throw ex;
        } catch (Throwable ex) {
            throw new RuntimeException(ex);
        }
    }
897174
public static Action charset(final String charset) {
        return new Action(r -> {
            r.setCharacterEncoding(charset);
            return r;
        });
    }
334835
public static void populateBean(final Object bean, 
        final Map<String, String> params) {
        final Method[] methods = bean.getClass().getMethods();
        for (final Method method : methods) {
            final Class<?>[] types = method.getParameterTypes();
            final int length = types.length;
            if (length != 1) {
                continue;
            }
            final String name = method.getName();
            if (!name.startsWith("set")) {
                continue;
            }
            final String fieldName = name.substring(3).toLowerCase();
            final String str = params.get(fieldName);
            if (str == null) {
                continue;
            }

            final String val = str.trim();
            
            final Class<?> type = types[0];
            
            final Object toAssign;
            if (type.isAssignableFrom(String.class)) {
                toAssign = val;
            }
            else if (type.isAssignableFrom(int.class)) {
                toAssign = Integer.parseInt(val);
            }
            else if (type.isAssignableFrom(boolean.class)) {
                toAssign = toBoolean(val);
            }
            else if (type.isAssignableFrom(Boolean.class)) {
                toAssign = toBoolean(val);
            }
            else if (type.isAssignableFrom(File.class)) {
                toAssign = new File(val);
            }
            else if (type.isAssignableFrom(URI.class)) {
                try {
                    toAssign = new URI(val);
                } catch (final URISyntaxException e) {
                    LOG.error("Error building bean", e);
                    throw new IllegalArgumentException("Error building bean",e);
                }
            }
            else if (type.isAssignableFrom(Integer.class)) {
                toAssign = Integer.parseInt(val);
            }
            else if (type.isAssignableFrom(int.class)) {
                toAssign = Integer.parseInt(val);
            }
            else if (type.isAssignableFrom(Float.class)) {
                toAssign = Float.parseFloat(val);
            }
            else if (type.isAssignableFrom(float.class)) {
                toAssign = Float.parseFloat(val);
            }
            else if (type.isAssignableFrom(Double.class)) {
                toAssign = Double.parseDouble(val);
            }
            else if (type.isAssignableFrom(double.class)) {
                toAssign = Double.parseDouble(val);
            }
            else if (type.isAssignableFrom(Long.class)) {
                toAssign = Long.parseLong(val);
            }
            else if (type.isAssignableFrom(long.class)) {
                toAssign = Long.parseLong(val);
            }
            else {
                final String msg = "Could not handle type: {}"+type.getName()+
                    " key: "+fieldName;
                LOG.error(msg);
                throw new IllegalArgumentException(msg);
            }
            try {
                method.invoke(bean, toAssign);
            } catch (final IllegalArgumentException e) {
                LOG.error("Could not invoke method", e);
            } catch (final IllegalAccessException e) {
                LOG.error("Could not invoke method", e);
            } catch (final InvocationTargetException e) {
                LOG.error("Could not invoke method", e);
            }
        }
    }
170340
public String getString(Charset charset) throws IOException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte cc = get();
        while (cc != 0)
        {
            baos.write(cc);
            cc = get();
        }
        byte[] buf = baos.toByteArray();
        return new String(buf, charset);
    }
531806
@Nonnull
    public static String readFile(@Nonnull File file, @Nonnull Charset charset) throws IOException {
        if (file == null)
            throw new NullPointerException("Given 'file' can not be null");
        if (!file.exists())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " does not exist");
        if (file.isDirectory())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " can NOT be a directory");

        InputStream in = new BufferedInputStream(new FileInputStream(file));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copy(in, bos);
        return new String(bos.toByteArray(), charset);

    }
1082000
public static BufferedReader asReader(InputStream is, Charset charset) {
		try {
			return new BufferedReader(new InputStreamReader(is, charset.toString()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
319970
@Nonnull
	public static String readInputStreamToString(@Nonnull final InputStream inputStream, @Nonnull final Charset charset)
			throws IOException {
		final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
		final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		int result = bufferedInputStream.read();
		while (result != -1) {
			byteArrayOutputStream.write((byte) result);
			result = bufferedInputStream.read();
		}
		return byteArrayOutputStream.toString(checkNonEmptyArgument(charset, "charset").name());
	}
1028747
private static String decodeFormFields (final String content, final String charset) {
        if (content == null) {
            return null;
        }
        return urldecode(content, charset != null ? Charset.forName(charset) : Consts.UTF_8, true);
    }
1305810
public T executeFrom(Object bean) {
    List<T> executeFromCollectionResult = executeFrom(Collections.singleton(bean));
    if (CollectionUtils.isEmpty(executeFromCollectionResult)) {
      return null;
    } else {
      return executeFromCollectionResult.get(0);
    }
  }
883958
protected void execute(final String[] args) throws Exception {
		// Process command-line.
		if (args.length == 0 || args.length == 1) {
			usage();
		}
		String userpass = args[0];
		String hostportOrPid = args[1];
		String beanname = null;// vGCutil
		String[] command = null;
		if (args.length > 2) {
			beanname = args[2];
		}
		if (args.length > 3) {
			command = new String[args.length - 3];
			for (int i = 3; i < args.length; i++) {
				command[i - 3] = args[i];
			}
		}
		String[] loginPassword = parseUserpass(userpass);

		// 模拟GC Util命令的扩展
		if (V_GCUTIL_BEAN_NAME.equalsIgnoreCase(beanname)) {
			// 支持配置interval 固定事件间隔连续输出
			int interval = 0;
			if (command != null && command.length > 0) {
				try {
					interval = Math.abs(Integer.parseInt(command[0]));// 拿绝对值, 避免负数的情况
				} catch (NumberFormatException e) {// NOSONAR
				}
			}

			ExtraCommand extraCommand = new ExtraCommand();
			extraCommand.execute(hostportOrPid, ((loginPassword == null) ? null : loginPassword[0]),
					((loginPassword == null) ? null : loginPassword[1]), beanname, interval);
			return;
		}

		Object[] result = execute(hostportOrPid, ((loginPassword == null) ? null : loginPassword[0]),
				((loginPassword == null) ? null : loginPassword[1]), beanname, command);
		if (result != null) {
			for (int i = 0; i < result.length; i++) {
				if (result[i] != null && result[i].toString().length() > 0) {
					if (command != null) {
						logger.info(command[i] + ": " + result[i]);
					} else {
						logger.info("\n" + result[i].toString());
					}
				}
			}
		}
	}
958569
public static byte[] sha224Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return sha224Hash(data.getBytes(charset));
	}
145191
private String readBeanName(Class beanClass) throws NoSuchFieldException, IllegalAccessException{
    final Field field = beanClass.getField("BEAN_NAME");
    return String.valueOf(field.get(null));
  }
489592
public static <T> Map<String, Object> toMap(T bean) {
        Map<String, Object> map = null;
        try {
            map = PropertyUtils.describe(bean);
            map.remove("class");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return map;
    }
557587
public static String readString(File file, Charset charset) throws IOException {
        if (file == null || !file.isFile()) {
            return null;
        }
        StringBuilder fileContent = new StringBuilder();

        BufferedReader reader = null;
        try {
            InputStreamReader is = new InputStreamReader(new FileInputStream(file), charset);
            reader = new BufferedReader(is);
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (!fileContent.toString().equals("")) {
                    fileContent.append("\r\n");
                }
                fileContent.append(line);
            }
            reader.close();
            return fileContent.toString();
        } finally {
            closeQuietly(reader);
        }
    }