Java源码示例:cn.hutool.core.io.IORuntimeException

示例1
@Override
protected void copyFile(File file) {
    String inputFile = Paths.get(fileProperties.getStoragePath(), file.getRelativePath(),
            file.getFilename()).toString();

    String filename = randomFileName(file.getFilename());
    String outputFile = Paths.get(fileProperties.getStoragePath(), file.getRelativePath(), filename).toString();

    try {
        FileUtil.copy(inputFile, outputFile, true);
    } catch (IORuntimeException e) {
        log.error("复制文件异常", e);
        throw new BizException("复制文件异常");
    }

    file.setFilename(filename);
    String url = file.getUrl();
    String newUrl = StrUtil.subPre(url, StrUtil.lastIndexOfIgnoreCase(url, StrPool.SLASH) + 1);
    file.setUrl(newUrl + filename);
}
 
示例2
@Override
protected void copyFile(File file) {
    String inputFile = Paths.get(fileProperties.getStoragePath(), file.getRelativePath(),
            file.getFilename()).toString();

    String filename = randomFileName(file.getFilename());
    String outputFile = Paths.get(fileProperties.getStoragePath(), file.getRelativePath(), filename).toString();

    try {
        FileUtil.copy(inputFile, outputFile, true);
    } catch (IORuntimeException e) {
        log.error("复制文件异常", e);
        throw new BizException("复制文件异常");
    }

    file.setFilename(filename);
    String url = file.getUrl();
    String newUrl = StrUtil.subPre(url, StrUtil.lastIndexOfIgnoreCase(url, StrPool.SLASH) + 1);
    file.setUrl(newUrl + filename);
}
 
示例3
/**
 * 获得multipart/form-data 表单内容<br>
 * 包括文件和普通表单数据<br>
 * 在同一次请求中,此方法只能被执行一次!
 * 
 * @return MultiPart表单
 * @throws IORuntimeException IO异常
 * @since 4.0.2
 */
public static MultipartFormData getMultipart() throws IORuntimeException {
	final MultipartFormData formData = new MultipartFormData();
	try {
		formData.parseRequest(getRequest());
	} catch (IOException e) {
		throw new IORuntimeException(e);
	}

	return formData;
}
 
示例4
/**
 * 获得PrintWriter
 * 
 * @return 获得PrintWriter
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getWriter() throws IORuntimeException {
	try {
		return getResponse().getWriter();
	} catch (IOException e) {
		throw new IORuntimeException(e);
	}
}
 
示例5
/**
 * 获取资源列表
 * @param path   path资源路径
 * @param loader 类加载器,如果为null则获取当前线程的类加载器
 */
public static List<URL> getResources(String path, ClassLoader loader){
    final Enumeration<URL> resources;
    if(loader == null){
        loader = ClassLoaderUtil.getClassLoader();
    }
    try {
        resources = loader.getResources(path);
    } catch (IOException e) {
        throw new IORuntimeException(e);
    }
    return CollUtil.newArrayList(resources);
}
 
示例6
/**
 * 获取请求体<br>
 * 调用该方法后,getParam方法将失效
 * 
 * @param request {@link ServletRequest}
 * @return 获得请求体
 * @since 4.0.2
 */
public static String getBody(ServletRequest request) {
	try {
		return IoUtil.read(request.getReader());
	} catch (IOException e) {
		throw new IORuntimeException(e);
	}
}
 
示例7
/**
 * 获取请求体byte[]<br>
 * 调用该方法后,getParam方法将失效
 * 
 * @param request {@link ServletRequest}
 * @return 获得请求体byte[]
 * @since 4.0.2
 */
public static byte[] getBodyBytes(ServletRequest request) {
	try {
		return IoUtil.readBytes(request.getInputStream());
	} catch (IOException e) {
		throw new IORuntimeException(e);
	}
}