通过public class ThirdCountriesBulletinItemWriter implements ItemWriter<ThirdCountriesDocumentDTO> {
private static final Logger LOGGER = LoggerFactory.getLogger(ThirdCountriesBulletinItemWriter.class);
private static final SimpleDateFormat MONTH_AND_YEAR_FORMAT = new SimpleDateFormat("yyyyMM");
private static final SimpleDateFormat FULL_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
private FileOutputStream fos;
private ZipOutputStream zos;
@Value("${third.countries.notif.out.location}")
protected String outputLocation;
protected File targetFolder;
@PostConstruct
public void initialize(){
targetFolder = new File(outputLocation);
}
@Override
public void write(List<? extends ThirdCountriesDocumentDTO> items){
ThirdCountriesDocumentDTO dto = items.get(0);
try{
if(!targetFolder.exists()){
LOGGER.info("Creating main directory");
setFilePermissions(targetFolder);
targetFolder.mkdir();
}
String formattedMonth = targetFolder + File.separator + MONTH_AND_YEAR_FORMAT.format(dto.getDocumentCreationDate());
File monthFolder = new File(formattedMonth);
if(!monthFolder.exists()){
LOGGER.debug("Creating month folder " + MONTH_AND_YEAR_FORMAT.format(dto.getDocumentCreationDate()) + " for country " + dto.getDossierNationality());
setFilePermissions(monthFolder);
monthFolder.mkdir();
}
fos = new FileOutputStream(monthFolder + File.separator + dto.getDossierNationality() + "-" + MONTH_AND_YEAR_FORMAT.format(dto.getDocumentCreationDate()) + ".zip");
zos = new ZipOutputStream(fos);
ZipEntry zipEntry = new ZipEntry(dto.getDossierNationality() + "-" + MONTH_AND_YEAR_FORMAT.format(dto.getDocumentCreationDate()));
String pdfName = generatePdfName(dto);
zos.putNextEntry(zipEntry);
LOGGER.debug("Writing pdf with name : " + pdfName);
zos.write(dto.getDocument());
zos.closeEntry();
}
catch (IOException e){
throw new SystemException("Error performing third country batch : " , e);
}
finally {
if(zos != null) IOUtils.closeQuietly(zos);
if(fos != null) IOUtils.closeQuietly(fos);
}
}
}
连接到远程服务器(A)之后,是否可以访问主机的文件夹/文件?
此服务器A可以访问我无法从计算机访问的另一台服务器(B)。我需要使用计算机上的一些配置文件在B上运行一些命令。
答案 0 :(得分:0)
我最终使用scp
将文件从计算机复制到A并在那里运行命令。