cn.hutool.core.io.IORuntimeException Java Examples

The following examples show how to use cn.hutool.core.io.IORuntimeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalAutoConfigure.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: LocalAutoConfigure.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ServletUtils.java    From yue-library with Apache License 2.0 5 votes vote down vote up
/**
 * 获得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;
}
 
Example #4
Source File: ServletUtils.java    From yue-library with Apache License 2.0 5 votes vote down vote up
/**
 * 获得PrintWriter
 * 
 * @return 获得PrintWriter
 * @throws IORuntimeException IO异常
 */
public static PrintWriter getWriter() throws IORuntimeException {
	try {
		return getResponse().getWriter();
	} catch (IOException e) {
		throw new IORuntimeException(e);
	}
}
 
Example #5
Source File: ResourcesUtils.java    From simple-robot-core with Apache License 2.0 5 votes vote down vote up
/**
 * 获取资源列表
 * @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);
}
 
Example #6
Source File: ServletUtils.java    From yue-library with Apache License 2.0 3 votes vote down vote up
/**
 * 获取请求体<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);
	}
}
 
Example #7
Source File: ServletUtils.java    From yue-library with Apache License 2.0 3 votes vote down vote up
/**
 * 获取请求体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);
	}
}