List of usage examples for java.io File setWritable
public boolean setWritable(boolean writable)
From source file:org.silverpeas.core.security.encryption.ContentEncryptionServiceTest.java
private void deleteSecurityDirectory() throws IOException { String securityPath = FileRepositoryManager.getSecurityDirPath(); File securityDir = new File(securityPath); if (securityDir.exists()) { File keyFile = new File(ACTUAL_KEY_FILE_PATH); if (keyFile.exists()) { keyFile.setWritable(true); FileUtils.forceDelete(keyFile); }/*from w ww .j a v a2 s. c o m*/ keyFile = new File(DEPRECATED_KEY_FILE_PATH); if (keyFile.exists()) { keyFile.setWritable(true); FileUtils.forceDelete(keyFile); } FileUtils.forceDelete(securityDir); } }
From source file:org.duracloud.stitch.FileStitcherDriver.java
private void writeContentToDir(Content content, File toDir) { File outFile = new File(toDir, content.getId()); log.info("Writing to '{}'.", outFile.getAbsolutePath()); OutputStream outputStream = null; try {//from ww w .jav a 2s.c o m // Create any needed subdirectories File parentDir = outFile.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); parentDir.setWritable(true); } // Write content outputStream = new FileOutputStream(outFile); IOUtils.copyLarge(content.getStream(), outputStream); } catch (IOException e) { StringBuilder msg = new StringBuilder(); msg.append("Error writing content: "); msg.append(content.getId()); msg.append(" to output file: "); msg.append(outFile.getAbsolutePath()); throw new DuraCloudRuntimeException(msg.toString(), e); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:beans.FotoBean.java
public void enviarArquivo(FileUploadEvent event) { try {/*from w ww . jav a 2 s.c o m*/ arquivo = gerarNome(); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String pasta = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "arquivossalvos"; File vpasta = new File(pasta); if (!vpasta.exists()) { vpasta.setWritable(true); vpasta.mkdirs(); } String novoarquivo = pasta + File.separator + event.getFile().getFileName(); File a = new File(novoarquivo); a.createNewFile(); FileUtils.copyInputStreamToFile(event.getFile().getInputstream(), a); byte[] fotobyte = FileUtils.readFileToByteArray(a); foto.setNome(event.getFile().getFileName()); foto.setArquivo(fotobyte); foto.setDataHora(Calendar.getInstance().getTime()); if (new FotoController().salvar(foto)) { listarArquivos(); Util.executarJavascript("PF('dlgfoto').hide()"); Util.criarMensagem("arquivo salvo"); Util.atualizarComponente("foto"); a.delete(); } } catch (Exception e) { Util.criarMensagemErro(e.toString()); } }
From source file:io.vertigo.struts2.FileDownloader4Tests.java
/** * Perform the file/image download.//from w w w. j a v a 2 s.co m * * @param element * @param attribute * @return downloadedFileAbsolutePath * @throws IOException * @throws NullPointerException */ private String downloader(final WebElement element, final String attribute) throws IOException, NullPointerException, URISyntaxException { final String fileToDownloadLocation = element.getAttribute(attribute); if (fileToDownloadLocation.trim().equals("")) { throw new NullPointerException("The element you have specified does not link to anything!"); } final URL fileToDownload = new URL(fileToDownloadLocation); final File downloadedFile = new TempFile(localDownloadPath, "test"); if (downloadedFile.canWrite() == false) { downloadedFile.setWritable(true); } try (final CloseableHttpClient client = HttpClientBuilder.create().build()) { final BasicHttpContext localContext = new BasicHttpContext(); LOG.info("Mimic WebDriver cookie state: " + mimicWebDriverCookieState); if (mimicWebDriverCookieState) { localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(driver.manage().getCookies())); } final HttpGet httpget = new HttpGet(fileToDownload.toURI()); final HttpParams httpRequestParameters = httpget.getParams(); httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects); httpget.setParams(httpRequestParameters); LOG.info("Sending GET request for: " + httpget.getURI()); try (final CloseableHttpResponse response = client.execute(httpget, localContext)) { httpStatusOfLastDownloadAttempt = response.getStatusLine().getStatusCode(); LOG.info("HTTP GET request status: " + httpStatusOfLastDownloadAttempt); LOG.info("Downloading file: " + downloadedFile.getName()); FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile); //response.getEntity().getContent().close(); } } final String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath(); LOG.info("File downloaded to '" + downloadedFileAbsolutePath + "'"); return downloadedFileAbsolutePath; }
From source file:org.apache.druid.indexing.common.tasklogs.FileTaskLogsTest.java
@Test public void testPushTaskLogDirCreationFails() throws Exception { final File tmpDir = temporaryFolder.newFolder(); final File logDir = new File(tmpDir, "druid/logs"); final File logFile = new File(tmpDir, "log"); Files.write("blah", logFile, StandardCharsets.UTF_8); if (!tmpDir.setWritable(false)) { throw new RuntimeException("failed to make tmp dir read-only"); }// w w w . j a va2 s. c o m final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir)); expectedException.expect(IOException.class); expectedException.expectMessage("Unable to create task log dir"); taskLogs.pushTaskLog("foo", logFile); }
From source file:com.supremainc.biostar2.sdk.volley.toolbox.JsonObjectRequest.java
private void writeLog(String filename, String data) { if (ConfigDataProvider.DEBUG_SDCARD) { if (data == null) { return; }//from w w w. ja va 2s. c om if (filename == null) { filename = ""; } File file = new File(Environment.getExternalStorageDirectory() + "/err"); if (!file.isDirectory()) { file.mkdirs(); file.setWritable(true); file.setReadable(true); } bufferToFile(Environment.getExternalStorageDirectory() + "/err/w_" + filename + System.currentTimeMillis() + ".txt", data.getBytes()); } }
From source file:com.flysystem.core.adapter.local.Local.java
private boolean setVisibilityPublic(File file) { boolean readable = file.setReadable(true); boolean executable = file.setExecutable(true); boolean writable = file.setWritable(true); return readable && executable && writable; }
From source file:edu.harvard.mcz.imagecapture.ThumbnailBuilder.java
@Override public void run() { int existsCounter = 0; // mkdir thumbs ; mogrify -path thumbs -resize 80x120 *.JPG if (startPoint.isDirectory() && (!startPoint.getName().equals("thumbs"))) { File thumbsDir = new File(startPoint.getPath() + File.separator + "thumbs"); log.debug(thumbsDir.getPath());// w w w. j ava2 s . c o m if (!thumbsDir.exists()) { thumbsDir.mkdir(); thumbsDir.setWritable(true); log.debug("Creating " + thumbsDir.getPath()); } File[] potentialFilesToThumb = startPoint.listFiles(); List<File> filesToThumb = new ArrayList<File>(); int filesToThumbCount = 0; for (int i = 0; i < potentialFilesToThumb.length; i++) { if (potentialFilesToThumb[i].getName().endsWith(".JPG")) { filesToThumb.add(potentialFilesToThumb[i]); filesToThumbCount++; } } if (filesToThumbCount > 0) { int targetWidth = 100; int targetHeight = 150; Iterator<File> i = filesToThumb.iterator(); while (i.hasNext()) { File file = i.next(); File output = new File(thumbsDir.getPath().concat(File.separator).concat(file.getName())); if (!output.exists()) { // don't overwrite existing thumnails try { BufferedImage img = ImageIO.read(file); BufferedImage thumbnail = Scalr.resize(img, Scalr.Method.BALANCED, Scalr.Mode.FIT_TO_WIDTH, targetWidth, targetHeight, Scalr.OP_ANTIALIAS); // img.createGraphics().drawImage(ImageIO.read(file).getScaledInstance(targetWidth, targetHeigh, Image.SCALE_SMOOTH),0,0,null); ImageIO.write(thumbnail, "jpg", output); thumbnailCounter++; } catch (IOException e1) { log.error(e1.getMessage(), e1); JOptionPane.showMessageDialog(null, e1.getMessage() + "\n", "Error", JOptionPane.ERROR_MESSAGE); } } else { existsCounter++; } } } else { String message = "No *.JPG files found in " + startPoint.getPath(); log.debug(message); } } String exists = ""; if (existsCounter > 0) { exists = "\nSkipped " + existsCounter + " existing thumbnails."; } JOptionPane.showMessageDialog(null, "Done building " + thumbnailCounter + " thumbnails in ./thumbs/" + exists, "Thumbnails Built.", JOptionPane.INFORMATION_MESSAGE); }
From source file:com.flysystem.core.adapter.local.Local.java
private boolean setVisibilityPrivate(File file) { boolean readable = file.setReadable(false); boolean executable = file.setExecutable(false); boolean writable = file.setWritable(false); return readable && executable && writable; }
From source file:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java
@Test public void testDownloadDestinationNotWritable() { File directory = new File(TEMPORARY_DIRECTORY); assertThat(directory.setWritable(false)).isTrue(); TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); DownloadListener downloadListener = Mockito.mock(DownloadListener.class); ttorrentDownloader.setDownloadListener(downloadListener); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); assertThat(directory.setWritable(true)).isTrue(); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadStart(TORRENT_FILE); Mockito.verify(downloadListener, Mockito.times(0)).onDownloadProgress(Mockito.anyString(), Mockito.anyInt());/*from w ww.j a v a 2s. c o m*/ Mockito.verify(downloadListener, Mockito.times(1)).onDownloadEnd(TORRENT_FILE, DownloadState.ERROR_DESTINATION_IS_NOT_WRITEABLE); }