List of usage examples for java.io File toString
public String toString()
From source file:com.symbian.driver.core.controller.ControllerUtilsTest.java
/** * Test method for 'com.symbian.driver.core.controller.ControllerUtils.checkPCPath(String, boolean)' *///from w w w . ja va2 s . co m public void testCheckPCPath() { try { File lDir = new File("src/com/symbian/driver/core/controller/C*.java"); File[] lFile = ModelUtils.checkPCPath(lDir.toString(), true); System.out.println("The List of files is: "); for (int i = 0; i < lFile.length; i++) { System.out.println("\tFile: " + lFile[i].getCanonicalPath()); } } catch (IOException e) { e.printStackTrace(); fail(); } }
From source file:no.dusken.aranea.control.TestImageController.java
@Test public void testResizeImage_Width() throws Exception { //creating image object. Image image = new Image(); image.setID(123L);/* w ww .j a v a 2 s .co m*/ //mocking imageSernice.getEntity method to return image object I just created. when(imageService.getEntity(123L)).thenReturn(image); //mocking imageFile. File imageFile = mock(File.class); //mocking imageFile.exists method to return true. when(imageFile.exists()).thenReturn(true); //mocking resizedImageFile File resizedImageFile = mock(File.class); when(resizedImageFile.toString()).thenReturn("resized"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addParameter("ID", "123"); request.addParameter("maxwidth", "30"); //mocking imageUtils.getImageFile(Image) when(imageUtils.getImageFile(image)).thenReturn(imageFile); //mocking imageUtils.resizeImage(imageFile, maxWidth, maxHeight) when(imageUtils.resizeImage(imageFile, 30, 0)).thenReturn(resizedImageFile); ModelAndView mav = imgController.handleRequestInternal(request, response); assertEquals("Resize image method is wrong.", mav.getModel().get("file"), resizedImageFile); assertEquals("Resized image is wrong", "resized", resizedImageFile.toString()); }
From source file:no.dusken.aranea.control.TestImageController.java
@Test public void testResizeImage_Height() throws Exception { //creating image object. Image image = new Image(); image.setID(123L);/*from ww w . j a v a2 s . c om*/ //mocking imageSernice.getEntity method to return image object I just created. when(imageService.getEntity(123L)).thenReturn(image); //mocking imageFile. File imageFile = mock(File.class); //mocking imageFile.exists method to return true. when(imageFile.exists()).thenReturn(true); //mocking resizedImageFile File resizedImageFile = mock(File.class); when(resizedImageFile.toString()).thenReturn("resized"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addParameter("ID", "123"); request.addParameter("maxheight", "30"); //mocking imageUtils.getImageFile(Image) when(imageUtils.getImageFile(image)).thenReturn(imageFile); //mocking imageUtils.resizeImage(imageFile, maxWidth, maxHeight) when(imageUtils.resizeImage(imageFile, 0, 30)).thenReturn(resizedImageFile); ModelAndView mav = imgController.handleRequestInternal(request, response); assertEquals("Resize image method is wrong.", mav.getModel().get("file"), resizedImageFile); assertEquals("Resized image is wrong", "resized", resizedImageFile.toString()); }
From source file:de.willuhn.jameica.hbci.server.KontoauszugPdfUtil.java
/** * Speichert den Kontoauszug im Dateisystem bzw. Messaging. * @param k der Kontoauszug. Er muss eine ID besitzen - also bereits gespeichert worden sein. * @param data die rohen Binaer-Daten./*from ww w .j a va2 s. com*/ * @throws RemoteException * @throws ApplicationException */ public static void receive(Kontoauszug k, byte[] data) throws RemoteException, ApplicationException { if (k == null) throw new ApplicationException(i18n.tr("Kein Kontoauszug angegeben")); if (data == null || data.length == 0) throw new ApplicationException(i18n.tr("Kein Daten angegeben")); final Konto konto = k.getKonto(); if (konto == null) throw new ApplicationException(i18n.tr("Kein Konto angegeben")); // Per Messaging speichern? if (MessagingAvailableConsumer.haveMessaging() && Boolean.parseBoolean(MetaKey.KONTOAUSZUG_STORE_MESSAGING.get(konto))) { QueryMessage qm = new QueryMessage(CHANNEL, data); Application.getMessagingFactory().getMessagingQueue("jameica.messaging.put").sendSyncMessage(qm); k.setUUID(qm.getData().toString()); k.store(); Logger.info("stored account statement data in messaging archive [id: " + k.getID() + ", uuid: " + k.getUUID() + "]"); return; } // Im Dateisystem speichern String path = createPath(konto, k); try { File file = new File(path).getCanonicalFile(); Logger.info("storing account statement data in file [id: " + k.getID() + ", file: " + file + "]"); File dir = file.getParentFile(); if (!dir.exists()) { Logger.info("auto-creating parent dir: " + dir); if (!dir.mkdirs()) throw new ApplicationException( i18n.tr("Erstellen des Ordners fehlgeschlagen. Ordner-Berechtigungen korrekt?")); } if (!dir.canWrite()) throw new ApplicationException(i18n.tr("Kein Schreibzugriff in {0}", dir.toString())); OutputStream os = null; try { File target = file; int i = 0; while (i < 10000) { // Checken, ob die Datei schon existiert. Wenn ja, haengen wir einen Zaehler hinten drin. // Um sicherzugehen, dass wir die Datei nicht ueberschreiben. if (!target.exists()) break; // OK, die Datei gibts schon. Wir haengen den Counter hinten an i++; target = indexedFile(file, i); } os = new BufferedOutputStream(new FileOutputStream(target)); os.write(data); k.setPfad(target.getParent()); k.setDateiname(target.getName()); k.store(); } finally { IOUtil.close(os); } } catch (IOException e) { Logger.error("unable to store account statement data in file: " + path, e); throw new ApplicationException( i18n.tr("Speichern des Kontoauszuges fehlgeschlagen: {0}", e.getMessage())); } }
From source file:com.norconex.committer.AbstractMappedCommitterTest.java
/** * Sets up a committer for testing./*from ww w . j av a 2 s . co m*/ * @throws IOException problem setting up committer */ @Before public void setup() throws IOException { committer = new StubCommitter(); File queue = tempFolder.newFolder("queue"); committer.setQueueDir(queue.toString()); committed = false; metadata.clear(); metadata.addString("myreference", defaultReference); }
From source file:dtool.engine.ModuleParseCache.java
protected String getKeyFromPath(File filePath) { return filePath.toString(); }
From source file:net.ftb.util.OSUtils.java
/** * Opens the given path with the default application * @param path The path/*from www . j av a 2 s . com*/ */ public static void open(File path) { if (!path.exists()) { return; } try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { Desktop.getDesktop().open(path); } else if (getCurrentOS() == OS.UNIX) { // Work-around to support non-GNOME Linux desktop environments with xdg-open installed if (new File("/usr/bin/xdg-open").exists() || new File("/usr/local/bin/xdg-open").exists()) { new ProcessBuilder("xdg-open", path.toString()).start(); } } } catch (Exception e) { Logger.logError("Could not open file", e); } }
From source file:com.ariht.maven.plugins.config.DirectoryReader.java
@SuppressWarnings("rawtypes") private Collection<File> getAllFiles(final File directory) { if (!directory.exists()) { log.warn("Directory does not exist: " + directory.getPath()); return EMPTY_FILE_LIST; }/*from ww w. jav a 2 s . c om*/ final Collection allFiles = FileUtils.listFiles(directory, TrueFileFilter.TRUE, DirectoryFileFilter.DIRECTORY); final Collection<File> files = new ArrayList<File>(allFiles.size()); for (final Object o : allFiles) { if (o != null && o instanceof File) { final File file = (File) o; if (isFileToIgnore(file)) { log.info("Ignoring: " + file.toString()); } else { log.debug("Adding file: " + file.toString()); files.add(file); } } else { log.warn("Not a file: " + ToStringBuilder.reflectionToString(o)); } } return files; }
From source file:com.ibm.watson.catalyst.corpus.CorpusBuilder.java
/** * Reads corpus documents from a directory. * @param aDirectory/*from w w w. j a v a 2s . co m*/ * @return */ protected List<E> getDocumentsFromDirectory(File aDirectory) { if (!aDirectory.isDirectory()) { System.out.println("Full path: " + aDirectory.getAbsolutePath()); throw new IllegalArgumentException(aDirectory + " is not a directory."); } List<E> result = new ArrayList<E>(); File[] files = aDirectory.listFiles(); assert (files != null); if (files.length == 0) { throw new IllegalArgumentException("No files in directory: " + aDirectory); } int numFiles = 0; for (File f : aDirectory.listFiles()) { if (!f.toString().endsWith(".xml")) continue; E d = getDocumentFromFile(f); //if (!d.isComplete()) continue; // if (!goodDocs.contains(d.getSourceDoc())) { // continue; // } result.add(d); if (++numFiles % 1000 == 0) { System.out.print(numFiles + " documents loaded.\r"); } } System.out.println(); if (result.size() == 0) { throw new IllegalStateException("No valid documents in directory: " + aDirectory); } return result; }
From source file:com.cloudera.sqoop.metastore.hsqldb.HsqldbMetaStore.java
/** * Determine the user's home directory and return a file path * under this root where the shared metastore can be placed. */// ww w . j a v a 2s. c o m private String getHomeDirFilePath() { String homeDir = System.getProperty("user.home"); File homeDirObj = new File(homeDir); File sqoopDataDirObj = new File(homeDirObj, ".sqoop"); File databaseFileObj = new File(sqoopDataDirObj, "shared-metastore.db"); return databaseFileObj.toString(); }