mirror of https://github.com/halo-dev/halo
Translate some exception message.
parent
8a1b9ccffe
commit
7f20a2d764
|
@ -40,7 +40,7 @@ public class RecoveryController {
|
||||||
@ApiParam("This file content type should be json")
|
@ApiParam("This file content type should be json")
|
||||||
@RequestPart("file") MultipartFile file) {
|
@RequestPart("file") MultipartFile file) {
|
||||||
if (optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false)) {
|
if (optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false)) {
|
||||||
throw new BadRequestException("You cannot migrate after blog installing");
|
throw new BadRequestException("不能在博客初始化完成之后迁移数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
recoveryService.migrateFromV0_4_3(file);
|
recoveryService.migrateFromV0_4_3(file);
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
try {
|
try {
|
||||||
ossClient.deleteObject(new DeleteObjectsRequest(ossBucketName).withKey(key));
|
ossClient.deleteObject(new DeleteObjectsRequest(ossBucketName).withKey(key));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FileOperationException("Failed to delete file " + key + " from AliYun", e);
|
throw new FileOperationException("附件 " + key + " 从阿里云删除失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
ossClient.shutdown();
|
ossClient.shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class LocalFileHandler implements FileHandler {
|
||||||
try {
|
try {
|
||||||
Files.delete(path);
|
Files.delete(path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileOperationException("Failed to delete " + key + " file", e);
|
throw new FileOperationException("附件 " + key + " 删除失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete thumb if necessary
|
// Delete thumb if necessary
|
||||||
|
@ -197,7 +197,7 @@ public class LocalFileHandler implements FileHandler {
|
||||||
log.warn("Thumbnail: [{}] way not exist", thumbnailPath.toString());
|
log.warn("Thumbnail: [{}] way not exist", thumbnailPath.toString());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileOperationException("Failed to delete " + thumbnailName + " thumbnail", e);
|
throw new FileOperationException("附件缩略图 " + thumbnailName + " 删除失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (!FileHandler.isImageType(file.getContentType())) {
|
if (!FileHandler.isImageType(file.getContentType())) {
|
||||||
log.error("Invalid extension: [{}]", file.getContentType());
|
log.error("Invalid extension: [{}]", file.getContentType());
|
||||||
throw new FileOperationException("Invalid extension for file " + file.getOriginalFilename() + ". Only \"jpeg, jpg, png, gif, bmp\" files are supported");
|
throw new FileOperationException("不支持的文件类型,仅支持 \"jpeg, jpg, png, gif, bmp\" 格式的图片");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
@ -79,7 +79,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
// Check status
|
// Check status
|
||||||
if (mapResponseEntity.getStatusCode().isError()) {
|
if (mapResponseEntity.getStatusCode().isError()) {
|
||||||
log.error("Server response detail: [{}]", mapResponseEntity.toString());
|
log.error("Server response detail: [{}]", mapResponseEntity.toString());
|
||||||
throw new FileOperationException("Smms server response error. status: " + mapResponseEntity.getStatusCodeValue());
|
throw new FileOperationException("SM.MS 服务状态异常,状态码: " + mapResponseEntity.getStatusCodeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get smms response
|
// Get smms response
|
||||||
|
@ -88,7 +88,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
// Check error
|
// Check error
|
||||||
if (!isResponseSuccessfully(smmsResponse)) {
|
if (!isResponseSuccessfully(smmsResponse)) {
|
||||||
log.error("Smms response detail: [{}]", smmsResponse);
|
log.error("Smms response detail: [{}]", smmsResponse);
|
||||||
throw new FileOperationException(smmsResponse == null ? "Smms response is null" : smmsResponse.getMsg()).setErrorData(smmsResponse);
|
throw new FileOperationException(smmsResponse == null ? "SM.MS 服务返回内容为空" : smmsResponse.getMsg()).setErrorData(smmsResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get response data
|
// Get response data
|
||||||
|
@ -128,7 +128,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (responseEntity.getStatusCode().isError()) {
|
if (responseEntity.getStatusCode().isError()) {
|
||||||
log.debug("Smms server response error: [{}]", responseEntity.toString());
|
log.debug("Smms server response error: [{}]", responseEntity.toString());
|
||||||
throw new FileOperationException("Smms server response error");
|
throw new FileOperationException("SM.MS 服务状态异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Smms response detail: [{}]", responseEntity.getBody());
|
log.debug("Smms response detail: [{}]", responseEntity.getBody());
|
||||||
|
@ -155,7 +155,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
static class SmmsResponse {
|
private static class SmmsResponse {
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public class SmmsFileHandler implements FileHandler {
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
static class SmmsResponseData {
|
private static class SmmsResponseData {
|
||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
// Write file
|
// Write file
|
||||||
boolean uploadSuccess = upYun.writeFile(upFilePath, file.getInputStream(), true, null);
|
boolean uploadSuccess = upYun.writeFile(upFilePath, file.getInputStream(), true, null);
|
||||||
if (!uploadSuccess) {
|
if (!uploadSuccess) {
|
||||||
throw new FileOperationException("Failed to upload file " + file.getOriginalFilename() + " to UpYun " + upFilePath);
|
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到又拍云失败" + upFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
String filePath = StringUtils.removeEnd(ossDomain, "/") + upFilePath;
|
String filePath = StringUtils.removeEnd(ossDomain, "/") + upFilePath;
|
||||||
|
@ -118,7 +118,7 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
log.warn("Failed to delete file " + filePath + " from UpYun");
|
log.warn("Failed to delete file " + filePath + " from UpYun");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FileOperationException("Failed to delete file " + key + " from UpYun", e);
|
throw new FileOperationException("附件从又拍云删除失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
|
||||||
boolean exist = existByName(linkParam.getName());
|
boolean exist = existByName(linkParam.getName());
|
||||||
|
|
||||||
if (exist) {
|
if (exist) {
|
||||||
throw new AlreadyExistsException("Link name " + linkParam.getName() + " has already existed").setErrorData(linkParam.getName());
|
throw new AlreadyExistsException("友情链接 " + linkParam.getName() + " 已存在").setErrorData(linkParam.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return create(linkParam.convertTo());
|
return create(linkParam.convertTo());
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class RecoveryServiceImpl implements RecoveryService {
|
||||||
log.debug("Migrated posts: [{}]", posts);
|
log.debug("Migrated posts: [{}]", posts);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException("Failed to read multipart file " + file.getOriginalFilename(), e);
|
throw new ServiceException("备份文件 " + file.getOriginalFilename() + " 读取失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
if (themeId.equals(getActivatedThemeId())) {
|
if (themeId.equals(getActivatedThemeId())) {
|
||||||
// Prevent to delete the activated theme
|
// Prevent to delete the activated theme
|
||||||
throw new BadRequestException("You can't delete the activated theme").setErrorData(themeId);
|
throw new BadRequestException("不能删除正在使用的主题").setErrorData(themeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -258,7 +258,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
// Delete theme cache
|
// Delete theme cache
|
||||||
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException("Failed to delete theme folder", e).setErrorData(themeId);
|
throw new ServiceException("主题删除失败", e).setErrorData(themeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException("Failed to read options file", e);
|
throw new ServiceException("读取主题配置文件失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
return add(themeTmpPath);
|
return add(themeTmpPath);
|
||||||
} catch (IOException | GitAPIException e) {
|
} catch (IOException | GitAPIException e) {
|
||||||
throw new ServiceException("Failed to fetch theme from remote " + uri, e);
|
throw new ServiceException("主题拉取失败 " + uri, e);
|
||||||
} finally {
|
} finally {
|
||||||
FileUtils.deleteFolderQuietly(tmpPath);
|
FileUtils.deleteFolderQuietly(tmpPath);
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
log.debug("Download response: [{}]", downloadResponse.getStatusCode());
|
log.debug("Download response: [{}]", downloadResponse.getStatusCode());
|
||||||
|
|
||||||
if (downloadResponse.getStatusCode().isError() || downloadResponse.getBody() == null) {
|
if (downloadResponse.getStatusCode().isError() || downloadResponse.getBody() == null) {
|
||||||
throw new ServiceException("Failed to download " + zipUrl + ", status: " + downloadResponse.getStatusCode());
|
throw new ServiceException("下载失败 " + zipUrl + ", 状态码: " + downloadResponse.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Downloaded [{}]", zipUrl);
|
log.debug("Downloaded [{}]", zipUrl);
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
|
||||||
try {
|
try {
|
||||||
configuration.setSharedVariable("settings", listAsMapBy(themeService.getActivatedThemeId()));
|
configuration.setSharedVariable("settings", listAsMapBy(themeService.getActivatedThemeId()));
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
throw new ServiceException("Save theme settings error", e);
|
throw new ServiceException("主题设置保存失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
|
||||||
if (user.getExpireTime() != null && user.getExpireTime().after(now)) {
|
if (user.getExpireTime() != null && user.getExpireTime().after(now)) {
|
||||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(user.getExpireTime().getTime() - now.getTime());
|
long seconds = TimeUnit.MILLISECONDS.toSeconds(user.getExpireTime().getTime() - now.getTime());
|
||||||
// If expired
|
// If expired
|
||||||
throw new ForbiddenException("You have been temporarily disabled,please try again " + HaloUtils.timeFormat(seconds) + " later").setErrorData(seconds);
|
throw new ForbiddenException("账号已被停用,请 " + HaloUtils.timeFormat(seconds) + " 后重试").setErrorData(seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
|
||||||
public User create(User user) {
|
public User create(User user) {
|
||||||
// Check user
|
// Check user
|
||||||
if (count() != 0) {
|
if (count() != 0) {
|
||||||
throw new BadRequestException("This blog already exists a blogger");
|
throw new BadRequestException("当前博客已有用户");
|
||||||
}
|
}
|
||||||
|
|
||||||
User createdUser = super.create(user);
|
User createdUser = super.create(user);
|
||||||
|
|
|
@ -1,31 +1,19 @@
|
||||||
package run.halo.app.utils;
|
package run.halo.app.utils;
|
||||||
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* Common utils
|
||||||
* 常用工具
|
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author ryanwang
|
* @author ryanwang
|
||||||
* @date : 2017/12/22
|
* @date : 2017/12/22
|
||||||
|
@ -165,187 +153,4 @@ public class HaloUtils {
|
||||||
}
|
}
|
||||||
return machineAddress.getHostAddress();
|
return machineAddress.getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 获取备份文件信息
|
|
||||||
// *
|
|
||||||
// * @param dir dir
|
|
||||||
// * @return List
|
|
||||||
// */
|
|
||||||
// public static List<BackupDto> getBackUps(String dir) {
|
|
||||||
// final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
|
||||||
// srcPathStr.append("/halo/backup/");
|
|
||||||
// srcPathStr.append(dir);
|
|
||||||
// final File srcPath = new File(srcPathStr.toString());
|
|
||||||
// final File[] files = srcPath.listFiles();
|
|
||||||
// final List<BackupDto> backupDtos = new ArrayList<>();
|
|
||||||
// BackupDto backupDto;
|
|
||||||
// // 遍历文件
|
|
||||||
// if (null != files) {
|
|
||||||
// for (File file : files) {
|
|
||||||
// if (file.isFile()) {
|
|
||||||
// if (StrUtil.equals(file.getName(), ".DS_Store")) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// backupDto = new BackupDto();
|
|
||||||
// backupDto.setFileName(file.getName());
|
|
||||||
// backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
|
|
||||||
// backupDto.setFileType(FileUtil.getType(file));
|
|
||||||
// backupDto.setFileSize(parseSize(file.length()));
|
|
||||||
// backupDto.setBackupType(dir);
|
|
||||||
// backupDtos.add(backupDto);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return backupDtos;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 转换文件大小
|
|
||||||
// *
|
|
||||||
// * @param size size
|
|
||||||
// * @return String
|
|
||||||
// */
|
|
||||||
// public static String parseSize(long size) {
|
|
||||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
|
||||||
// return size + "B";
|
|
||||||
// } else {
|
|
||||||
// size = size / 1024;
|
|
||||||
// }
|
|
||||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
|
||||||
// return size + "KB";
|
|
||||||
// } else {
|
|
||||||
// size = size / 1024;
|
|
||||||
// }
|
|
||||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
|
||||||
// size = size * 100;
|
|
||||||
// return size / 100 + "." + size % 100 + "MB";
|
|
||||||
// } else {
|
|
||||||
// size = size * 100 / 1024;
|
|
||||||
// return size / 100 + "." + size % 100 + "GB";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件创建时间
|
|
||||||
*
|
|
||||||
* @param srcPath 文件绝对路径
|
|
||||||
* @return 时间
|
|
||||||
*/
|
|
||||||
public static Date getCreateTime(String srcPath) {
|
|
||||||
try {
|
|
||||||
BasicFileAttributes basicFileAttributes = Files.readAttributes(Paths.get(srcPath), BasicFileAttributes.class);
|
|
||||||
return new Date(basicFileAttributes.creationTime().toMillis());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to open the " + srcPath + " file", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件长和宽
|
|
||||||
*
|
|
||||||
* @param file file
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public static String getImageWh(File file) {
|
|
||||||
try {
|
|
||||||
final BufferedImage image = ImageIO.read(new FileInputStream(file));
|
|
||||||
return image.getWidth() + "x" + image.getHeight();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to get read image file", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出为文件
|
|
||||||
*
|
|
||||||
* @param data 内容
|
|
||||||
* @param filePath 保存路径
|
|
||||||
* @param fileName 文件名
|
|
||||||
*/
|
|
||||||
public static void postToFile(String data, String filePath, String fileName) throws IOException {
|
|
||||||
FileWriter fileWriter = null;
|
|
||||||
BufferedWriter bufferedWriter = null;
|
|
||||||
try {
|
|
||||||
final File file = new File(filePath);
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.mkdirs();
|
|
||||||
}
|
|
||||||
fileWriter = new FileWriter(file.getAbsoluteFile() + "/" + fileName, true);
|
|
||||||
bufferedWriter = new BufferedWriter(fileWriter);
|
|
||||||
bufferedWriter.write(data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to export file", e);
|
|
||||||
} finally {
|
|
||||||
if (null != bufferedWriter) {
|
|
||||||
bufferedWriter.close();
|
|
||||||
}
|
|
||||||
if (null != fileWriter) {
|
|
||||||
fileWriter.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 百度主动推送
|
|
||||||
*
|
|
||||||
* @param blogUrl 博客地址
|
|
||||||
* @param token 百度推送token
|
|
||||||
* @param urls 文章路径
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public static String baiduPost(String blogUrl, String token, String urls) {
|
|
||||||
Assert.hasText(blogUrl, "blog url must not be blank");
|
|
||||||
Assert.hasText(token, "token must not be blank");
|
|
||||||
Assert.hasText(urls, "urls must not be blank");
|
|
||||||
|
|
||||||
final StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
|
|
||||||
url.append(blogUrl);
|
|
||||||
url.append("&token=");
|
|
||||||
url.append(token);
|
|
||||||
|
|
||||||
final StrBuilder result = new StrBuilder();
|
|
||||||
PrintWriter out = null;
|
|
||||||
BufferedReader in = null;
|
|
||||||
try {
|
|
||||||
// 建立URL之间的连接
|
|
||||||
final URLConnection conn = new URL(url.toString()).openConnection();
|
|
||||||
// 设置通用的请求属性
|
|
||||||
conn.setRequestProperty("Host", "data.zz.baidu.com");
|
|
||||||
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
|
||||||
conn.setRequestProperty("Content-Length", "83");
|
|
||||||
conn.setRequestProperty("Content-Type", "text/plain");
|
|
||||||
|
|
||||||
// 发送POST请求必须设置如下两行
|
|
||||||
conn.setDoInput(true);
|
|
||||||
conn.setDoOutput(true);
|
|
||||||
|
|
||||||
// 获取conn对应的输出流
|
|
||||||
out = new PrintWriter(conn.getOutputStream());
|
|
||||||
out.print(urls.trim());
|
|
||||||
// 进行输出流的缓冲
|
|
||||||
out.flush();
|
|
||||||
// 通过BufferedReader输入流来读取Url的响应
|
|
||||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
||||||
String line;
|
|
||||||
while ((line = in.readLine()) != null) {
|
|
||||||
result.append(line);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to push posts to baidu", e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (null != out) {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
if (null != in) {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// Ignore this exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue