List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:de.ecw.zabos.license.License.java
/** * License-File einlesen und dekodieren// w ww .java2 s.c o m * * @param _licensePath * @return */ public boolean readLicense(Resource _licensePath) { try { if (!_licensePath.exists()) { throw new Exception("Lizenz-Datei [" + _licensePath.toString() + "] nicht gefunden"); } File f = _licensePath.getFile(); FileInputStream ifs = new FileInputStream(f); byte[] senc = new byte[512]; if (f.length() != 512) { // Filegroesse stimmt nicht return false; } int i; for (i = 0; i < 512; i++) { senc[i] = (byte) ((ifs.read() ^ xor_key[i]) & 0xFF); } // Bits extrahieren byte[] uenc = new byte[64]; int off = 0; for (i = 0; i < 64; i++) { uenc[i] = (byte) (((senc[off + 0] & 0x01)) | (((senc[off + 1]) & 0x02)) | (((senc[off + 2]) & 0x04)) | (((senc[off + 3]) & 0x08)) | (((senc[off + 4]) & 0x10)) | (((senc[off + 5]) & 0x20)) | (((senc[off + 6]) & 0x40)) | (((senc[off + 7]) & 0x80))); off += 8; } // Felder extrahieren long t; long aus; aus = (uenc[OFF_AUSSTELLUNGSDATUM + 0] & 0xFF); t = (uenc[OFF_AUSSTELLUNGSDATUM + 1] & 0xFF); aus |= t << 8; t = (uenc[OFF_AUSSTELLUNGSDATUM + 2] & 0xFF); aus |= t << 16; t = (uenc[OFF_AUSSTELLUNGSDATUM + 3] & 0xFF); aus |= t << 24; t = (uenc[OFF_AUSSTELLUNGSDATUM + 4] & 0xFF); aus |= t << 32; t = (uenc[OFF_AUSSTELLUNGSDATUM + 5] & 0xFF); aus |= t << 40; t = (uenc[OFF_AUSSTELLUNGSDATUM + 6] & 0xFF); aus |= t << 48; t = (uenc[OFF_AUSSTELLUNGSDATUM + 7] & 0xFF); aus |= t << 56; ausstellungsdatum = new UnixTime(aus); long ab; ab = (uenc[OFF_ABLAUFDATUM + 0] & 0xFF); t = (uenc[OFF_ABLAUFDATUM + 1] & 0xFF); ab |= t << 8; t = (uenc[OFF_ABLAUFDATUM + 2] & 0xFF); ab |= t << 16; t = (uenc[OFF_ABLAUFDATUM + 3] & 0xFF); ab |= t << 24; t = (uenc[OFF_ABLAUFDATUM + 4] & 0xFF); ab |= t << 32; t = (uenc[OFF_ABLAUFDATUM + 5] & 0xFF); ab |= t << 40; t = (uenc[OFF_ABLAUFDATUM + 6] & 0xFF); ab |= t << 48; t = (uenc[OFF_ABLAUFDATUM + 7] & 0xFF); ab |= t << 56; ablaufdatum = new UnixTime(ab); kundennummer = (uenc[OFF_KUNDENNUMMER + 0] & 0xFF) | ((uenc[OFF_KUNDENNUMMER + 1] & 0xFF) << 8) | ((uenc[OFF_KUNDENNUMMER + 2] & 0xFF) << 16) | ((uenc[OFF_KUNDENNUMMER + 3] & 0xFF) << 24); majorVersion = uenc[OFF_MAJOR_VERSION]; minorVersion = uenc[OFF_MINOR_VERSION]; schleifen = (short) ((uenc[OFF_SCHLEIFEN + 0] & 0xFF) | ((uenc[OFF_SCHLEIFEN + 1] & 0xFF) << 8)); personen = (short) ((uenc[OFF_PERSONEN + 0] & 0xFF) | ((uenc[OFF_PERSONEN + 1] & 0xFF) << 8)); off = OFF_USER; i = 0; StringBuffer sb = new StringBuffer(); while ((i++ < 18) && (uenc[off] != 0)) { sb.append((char) (uenc[off++] & 0xFF)); } user = sb.toString(); off = OFF_PASSWD; i = 0; sb = new StringBuffer(); while ((i++ < 18) && (uenc[off] != 0)) { sb.append((char) (uenc[off++] & 0xFF)); } passwd = sb.toString(); // Debug System.err.println("===================================="); System.err.println(" ZABOS LIZENZ INFORMATIONEN:"); System.err.println("===================================="); System.err.println("Ausstellungsdatum: " + ausstellungsdatum); System.err.println("Ablaufdatum: " + ablaufdatum); System.err.println("Kundennummer: " + kundennummer); System.err.println("Version: " + majorVersion + "." + minorVersion); System.err.println("Schleifen: " + schleifen); System.err.println("Personen: " + personen); System.err.println("Gateway-User: " + user); System.err.println("Gateway-Passwd: xxx"); return true; } catch (Exception e) { System.err.println("Die Lizenz-Datei " + _licensePath + " konnte nicht geoeffnet werden (cwd=\"" + System.getProperty("user.dir") + "\")"); e.printStackTrace(); } return false; }
From source file:com.multimedia.service.wallpaper.WallpaperServiceImpl.java
public void setPath(Resource res) { try {/*from www . j a v a2 s . com*/ File f = res.getFile(); if (f.exists()) { if (f.isFile()) { f.delete(); f.mkdir(); } } else { f.mkdirs(); //f.mkdir(); } if (f.exists() && f.isDirectory()) path = f.getCanonicalPath() + "/"; else throw new NullPointerException("image folder not found for " + getClass()); } catch (IOException e) { path = null; throw new NullPointerException("image folder not found" + getClass()); } //System.out.println("----------------------------path = "+this.path); }
From source file:com.multimedia.service.wallpaper.WallpaperServiceImpl.java
public void setResized_path(Resource res) { try {//from w ww .j a v a 2s . c o m File f = res.getFile(); if (f.exists()) { if (f.isFile()) { f.delete(); f.mkdir(); } } else { f.mkdirs(); //f.mkdir(); } if (f.exists() && f.isDirectory()) resized_path = f.getCanonicalPath() + "/"; else throw new NullPointerException("image resized folder not found for " + getClass()); } catch (IOException e) { resized_path = null; throw new NullPointerException("image resized folder not found" + getClass()); } //System.out.println("----------------------------path = "+this.path); }
From source file:com.multimedia.service.wallpaper.WallpaperServiceImpl.java
public void setBackup_path(Resource res) { try {/*ww w . ja v a 2s. co m*/ File f = res.getFile(); if (f.exists()) { if (f.isFile()) { f.delete(); f.mkdir(); } } else { f.mkdirs(); //f.mkdir(); } if (f.exists() && f.isDirectory()) backup_path = f.getCanonicalPath() + "/"; else throw new NullPointerException("backup folder not found for " + getClass()); } catch (IOException e) { backup_path = null; throw new NullPointerException("backup folder not found for " + getClass()); } //System.out.println("----------------------------path = "+this.path); }
From source file:com.multimedia.service.wallpaper.WallpaperServiceImpl.java
public void setUpload_path(Resource res) { try {/* w w w.ja v a 2 s. com*/ File f = res.getFile(); if (f.exists()) { if (f.isFile()) { f.delete(); f.mkdir(); } } else { f.mkdirs(); //f.mkdir(); } if (f.exists() && f.isDirectory()) upload_path = f.getCanonicalPath() + "/"; else throw new NullPointerException("upload folder not found for " + getClass()); } catch (IOException e) { upload_path = null; throw new NullPointerException("upload folder not found for " + getClass()); } //System.out.println("----------------------------path = "+this.path); }
From source file:org.activiti.spring.SpringProcessEngineConfiguration.java
protected void autoDeployResources(ProcessEngine processEngine) { if (deploymentResources != null && deploymentResources.length > 0) { RepositoryService repositoryService = processEngine.getRepositoryService(); DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering() .name(deploymentName);// ww w. j av a 2 s . c om for (Resource resource : deploymentResources) { String resourceName = null; if (resource instanceof ContextResource) { resourceName = ((ContextResource) resource).getPathWithinContext(); } else if (resource instanceof ByteArrayResource) { resourceName = resource.getDescription(); } else { try { resourceName = resource.getFile().getAbsolutePath(); } catch (IOException e) { resourceName = resource.getFilename(); } } try { if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) { deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream())); } else { deploymentBuilder.addInputStream(resourceName, resource.getInputStream()); } } catch (IOException e) { throw new ActivitiException( "couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e); } } deploymentBuilder.deploy(); } }
From source file:fr.acxio.tools.agia.tasks.FilesOperationTaskletTest.java
@Test public void testExecuteCopyNullDestinationFactory() throws Exception { exception.expect(IllegalArgumentException.class); FilesOperationTasklet aTasklet = new FilesOperationTasklet(); ResourcesFactory aSourceFactory = mock(ResourcesFactory.class); Resource aFileResource1 = mock(Resource.class); when(aFileResource1.getFile()).thenReturn(new File("src/test/resources/testFiles/input.csv")); when(aFileResource1.exists()).thenReturn(true); when(aSourceFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource1 }); aTasklet.setSourceFactory(aSourceFactory); aTasklet.setDestinationFactory(null); aTasklet.setOperation(Operation.COPY); aTasklet.afterPropertiesSet();// w ww . j a v a2s. c o m aTasklet.execute(null, null); }
From source file:fr.acxio.tools.agia.tasks.FilesOperationTaskletTest.java
@Test public void testExecuteCopyNullDestination() throws Exception { exception.expect(FileOperationException.class); FilesOperationTasklet aTasklet = new FilesOperationTasklet(); ResourcesFactory aSourceFactory = mock(ResourcesFactory.class); Resource aFileResource1 = mock(Resource.class); when(aFileResource1.getFile()).thenReturn(new File("src/test/resources/testFiles/input.csv")); when(aFileResource1.exists()).thenReturn(true); when(aSourceFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource1 }); ResourceFactory aDestinationFactory = mock(ResourceFactory.class); aTasklet.setSourceFactory(aSourceFactory); aTasklet.setDestinationFactory(aDestinationFactory); aTasklet.setOperation(Operation.COPY); aTasklet.afterPropertiesSet();/* w w w .j av a 2 s . c o m*/ aTasklet.execute(null, null); }
From source file:fr.acxio.tools.agia.tasks.FilesOperationTaskletTest.java
@Test public void testExecuteRemove() throws Exception { FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/CP-input.csv")); FilesOperationTasklet aTasklet = new FilesOperationTasklet(); ResourcesFactory aSourceFactory = mock(ResourcesFactory.class); Resource aFileResource1 = mock(Resource.class); when(aFileResource1.getFile()).thenReturn(new File("target/CP-input.csv")); when(aFileResource1.exists()).thenReturn(true); when(aSourceFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource1 }); aTasklet.setSourceFactory(aSourceFactory); aTasklet.setOperation(Operation.REMOVE); aTasklet.afterPropertiesSet();//from ww w . j a v a 2s . c o m StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(1)).incrementReadCount(); verify(aStepContribution, times(1)).incrementWriteCount(1); assertFalse(aFileResource1.getFile().exists()); }