List of usage examples for org.springframework.util ResourceUtils getFile
public static File getFile(URI resourceUri) throws FileNotFoundException
From source file:com.nhncorp.hangeul.admin.manage.bo.HangeulManageBOImpl.java
/** * 1, 2 //from w ww. j a v a2 s . co m * @param articleParam * @return * @see com.nhncorp.hangeul.admin.work.bo.HangeulWorkManageBO#deleteArticles(com.nhncorp.hangeul.admin.work.model.ArticleParam) */ @Override @Transactional public int deleteArticles(int entySeq, String hangeulWorkType, String imgPath) throws Exception { int deleteCount = 0; boolean fileDeleteResult = false; String fileId = null; LOG.debug("********** hangeulWorkType == " + hangeulWorkType + ", imgPath == " + imgPath); if (StringUtils.isEmpty(hangeulWorkType) || StringUtils.isEmpty(imgPath)) { return deleteCount; } if (StringUtils.equals(hangeulWorkType, "IMAGE")) { fileId = hangeulWorkManageDAO.selectHangeulWork(entySeq, hangeulWorkType); LOG.debug("*** fileId == " + fileId); } // ? if (StringUtils.equals(hangeulWorkType, "IMAGE")) { File file = ResourceUtils.getFile(imgPath + fileId); boolean exists = file.exists(); LOG.debug("********** fileFullPath == " + imgPath + fileId); LOG.debug("********** exists == " + exists); if (exists == true) { fileDeleteResult = file.delete(); LOG.debug("********** , fileDeleteResult == " + fileDeleteResult); } } else { fileDeleteResult = true; } // DB if (fileDeleteResult == true) { hangeulWorkManageDAO.deleteArticle(entySeq, hangeulWorkType); deleteCount++; } return deleteCount; }
From source file:com.thoughtworks.go.util.Log4jDirectConfigurer.java
private boolean isLog4jExist() throws IOException { File file = ResourceUtils.getFile(log4jLocation); if (log4jExistInPath(file)) { doExistAction(file.getAbsolutePath()); return true; }//from www . j a v a 2 s .c o m URL resource = Loader.getResource(log4jLocation); if (log4JExistInClassPath(resource)) { doExistAction(resource.toString()); return true; } return false; }
From source file:com.wavemaker.tools.javaservice.JavaServiceDefinition2Test.java
private ServiceDefinition getServiceDefFromJar(String jarFileName) throws Exception { List<File> classRoots = new ArrayList<File>(); List<File> jarDirs = new ArrayList<File>(); File jarDir = IOUtils.createTempDirectory(); File srcJarFile = new ClassPathResource( this.getClass().getPackage().getName().replace(".", "/") + "/" + jarFileName).getFile(); File jarFile = new File(jarDir, jarFileName); FileUtils.copyFile(srcJarFile, jarFile); jarDirs.add(jarDir);/*from ww w .j a va2 s. c om*/ ClassPathResource runtimeServiceResource = new ClassPathResource( "com/wavemaker/runtime/service/LiveDataService.class"); if (ResourceUtils.isJarURL(runtimeServiceResource.getURL())) { URL jarUrl = ResourceUtils.extractJarFileURL(runtimeServiceResource.getURL()); jarDirs.add(ResourceUtils.getFile(jarUrl).getParentFile()); } else { File runtimeServiceClassFile = runtimeServiceResource.getFile(); File runtimeClassRoot = runtimeServiceClassFile.getParentFile().getParentFile().getParentFile() .getParentFile().getParentFile(); classRoots.add(runtimeClassRoot); } ServiceDefinition ret = new JavaServiceDefinition("Foo", "serviceId", classRoots, jarDirs, new ArrayList<String>()); jarFile.delete(); jarDir.delete(); return ret; }
From source file:com.wavemaker.tools.javaservice.JavaServiceDefinition2Test.java
private ServiceDefinition getServiceDef(String className, List<File> serviceLibDirs) throws Exception { List<File> classRoots = new ArrayList<File>(); serviceLibDirs = serviceLibDirs == null ? new ArrayList<File>() : serviceLibDirs; File classFile = new ClassPathResource(className.replace('.', '/') + ".class").getFile(); File classRoot = classFile.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile(); classRoots.add(classRoot);//from ww w . ja v a 2 s . com File queryInfoClassFile = new ClassPathResource( JavaService_BeanClass.class.getName().replace('.', '/') + ".class").getFile(); File queryInfoClassRoot = queryInfoClassFile.getParentFile().getParentFile().getParentFile().getParentFile() .getParentFile(); classRoots.add(queryInfoClassRoot); ClassPathResource runtimeServiceResource = new ClassPathResource( LiveDataService.class.getName().replace(".", "/") + ".class"); if (ResourceUtils.isJarURL(runtimeServiceResource.getURL())) { URL jarUrl = ResourceUtils.extractJarFileURL(runtimeServiceResource.getURL()); serviceLibDirs.add(ResourceUtils.getFile(jarUrl).getParentFile()); } else { File runtimeServiceClassFile = runtimeServiceResource.getFile(); File runtimeClassRoot = runtimeServiceClassFile.getParentFile().getParentFile().getParentFile() .getParentFile().getParentFile(); classRoots.add(runtimeClassRoot); } ClassPathResource typeDefinitionResource = new ClassPathResource( TypeDefinition.class.getName().replace(".", "/") + ".class"); if (ResourceUtils.isJarURL(typeDefinitionResource.getURL())) { URL jarUrl = ResourceUtils.extractJarFileURL(typeDefinitionResource.getURL()); serviceLibDirs.add(ResourceUtils.getFile(jarUrl).getParentFile()); } else { File typeDefinitionClassFile = typeDefinitionResource.getFile(); File typeDefinitionClassRoot = typeDefinitionClassFile.getParentFile().getParentFile().getParentFile() .getParentFile().getParentFile(); classRoots.add(typeDefinitionClassRoot); } return new JavaServiceDefinition(className, "serviceId", classRoots, serviceLibDirs, new ArrayList<String>()); }
From source file:com.wavemaker.tools.ws.WSDLTest.java
public static JAXBTypeMapper buildJAXBTypeMapper(WSDL wsdl, List<String> bindingResources) throws Exception { List<File> bindingFiles = new ArrayList<File>(); if (bindingResources != null) { for (String bindingResource : bindingResources) { if (log.isDebugEnabled()) { log.debug("Loading resource " + bindingResource + " for JAXB type mapper."); }//from www . j a v a 2s . co m File bindingFile = ResourceUtils.getFile("classpath:" + bindingResource); bindingFiles.add(bindingFile); } } JAXBTypeMapper mapper = new JAXBTypeMapper(wsdl, convertToFileSystemFileList(bindingFiles)); return mapper; }
From source file:com.yqboots.dict.context.DataDictImportListener.java
/** * {@inheritDoc}/*from www. j a va 2s . co m*/ */ @Override public void onApplicationEvent(final ContextRefreshedEvent event) { final ApplicationContext context = event.getApplicationContext(); final DataDictManager manager = context.getBean(DataDictManager.class); final DataDictProperties properties = context.getBean(DataDictProperties.class); if (!properties.isImportEnabled()) { return; } final String location = properties.getImportFileLocation(); if (StringUtils.isEmpty(location)) { LOG.warn("Data Dict Importing is enabled, but location was not set"); return; } try { final File file = ResourceUtils.getFile(location); try (final InputStream inputStream = new FileInputStream(file)) { manager.imports(inputStream); } } catch (IOException e) { LOG.error("Failed to import Data Dicts", e); } }
From source file:com.yqboots.menu.context.MenuItemImportListener.java
/** * {@inheritDoc}//from www.j av a2 s . c o m */ @Override public void onApplicationEvent(final ContextRefreshedEvent event) { final ApplicationContext context = event.getApplicationContext(); final MenuItemManager manager = context.getBean(MenuItemManager.class); final MenuItemProperties properties = context.getBean(MenuItemProperties.class); // ignore if importing is disabled if (!properties.isImportEnabled()) { return; } // find importing file in the specified location final String location = properties.getImportFileLocation(); if (StringUtils.isEmpty(location)) { LOG.warn("Menu Item Importing is enabled, but location was not set"); return; } try { // get file, may throw FileNotFoundException final File file = ResourceUtils.getFile(location); try (final InputStream inputStream = new FileInputStream(file)) { manager.imports(inputStream); } } catch (IOException e) { LOG.error("Failed to import Menu Items", e); } }
From source file:com.yqboots.web.thymeleaf.support.Html2PdfGenerator.java
/** * Add fonts to {@link ITextRenderer}, for chinese support. * * @param renderer renderer//from w ww. j a v a2s . c o m * @param fonts fonts * @throws Exception */ private void addFonts(final ITextRenderer renderer, final String[] fonts) throws Exception { if (ArrayUtils.isEmpty(fonts)) { return; } Assert.notNull(renderer); final ITextFontResolver fontResolver = renderer.getFontResolver(); for (final String font : fonts) { final String fontPath = ResourceUtils.getFile(font).getAbsolutePath(); fontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } }
From source file:integration.BfPixelBufferTest.java
private void setUpTestFile(String fileName) throws Throwable, NoSuchAlgorithmException { File srcFile = ResourceUtils.getFile("classpath:" + fileName); String dataDirName = root.getSession().getConfigService().getConfigValue("omero.data.dir"); String destPathName = UUID.randomUUID().toString(); File dataDir = new File(dataDirName); destPath = new File(dataDir, destPathName); File destFile = new File(destPath, fileName); destPath.mkdir();/* w ww.j a v a2s.c om*/ // Copy file into repo FileUtils.copyFile(srcFile, destFile); // Import file List<Pixels> pixList = importFile(srcFile, fileName); log.debug(String.format("Imported: %s, pixid: %d", srcFile, pixList.get(0).getId().getValue())); // Access the imported pixels via a RawPixelsStore rps = factory.createRawPixelsStore(); rps.setPixelsId(pixList.get(0).getId().getValue(), false); // Access the data from file via BfPixelBuffer destFileName = destFile.getCanonicalPath(); bf = new BfPixelBuffer(destFileName, new ImageReader()); }
From source file:integration.DiskUsageTest.java
/** * Import a test image and note information related to it. * @throws Throwable unexpected//from w ww . j a v a 2s.c om */ @BeforeClass public void setup() throws Throwable { ec = iAdmin.getEventContext(); final File imageFile = ResourceUtils.getFile("classpath:tinyTest.d3d.dv"); fileSize = imageFile.length(); final Pixels pixels = importFile(imageFile, "dv").get(0); pixelsId = pixels.getId().getValue(); imageId = pixels.getImage().getId().getValue(); final ManageImageBinaries mibRequest = new ManageImageBinaries(); mibRequest.imageId = imageId; final ManageImageBinariesResponse mibResponse = (ManageImageBinariesResponse) doChange(mibRequest); thumbnailSize = mibResponse.thumbnailSize; Assert.assertNotNull(ec); Assert.assertNotNull(imageId); Assert.assertNotNull(pixelsId); Assert.assertNotNull(fileSize); Assert.assertNotNull(thumbnailSize); }