List of usage examples for java.io File setReadable
public boolean setReadable(boolean readable)
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: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:com.streamsets.datacollector.cluster.TestTarFileCreator.java
@Test(expected = IllegalStateException.class) public void testCreateEtcTarGzFileDirIsNotReadable() throws Exception { File etcDir = new File(tempDir, "etc"); Assert.assertTrue(etcDir.mkdir());/*from ww w. jav a2 s .com*/ etcDir.setReadable(false); File tarFile = new File(tempDir, "etc.tar.gz"); TarFileCreator.createTarGz(etcDir, tarFile); }
From source file:org.marketcetera.saclient.CreateStrategyParametersTest.java
/** * Verifies all constructor parameter checks. * * @throws Exception if there were unexpected test failures. *///from www . j a v a2 s .c om @Test public void constructorChecks() throws Exception { //strategy name new ExpectedFailure<NullPointerException>() { @Override protected void run() throws Exception { new CreateStrategyParameters("blah", null, "JAVA", new File("dontmatter"), null, false); } }; //language new ExpectedFailure<NullPointerException>() { @Override protected void run() throws Exception { new CreateStrategyParameters("blah", "naah", null, new File("dontmatter"), null, false); } }; //strategy script new ExpectedFailure<NullPointerException>() { @Override protected void run() throws Exception { new CreateStrategyParameters("blah", "naah", "JAVA", null, null, false); } }; //non existent strategy script final File source = new File("doesnotexist"); new ExpectedFailure<FileNotFoundException>(source.getAbsolutePath()) { @Override protected void run() throws Exception { new CreateStrategyParameters("blah", "naah", "JAVA", source, null, false); } }; //non readable strategy script final File unreadable = File.createTempFile("strat", "txt"); unreadable.deleteOnExit(); unreadable.setReadable(false); unreadable.setReadable(false, false); //test unreadability failure only if we can make the file unreadable. if (!unreadable.canRead()) { new ExpectedFailure<FileNotFoundException>(unreadable.getAbsolutePath()) { @Override protected void run() throws Exception { new CreateStrategyParameters("blah", "naah", "JAVA", unreadable, null, false); } }; } else { SLF4JLoggerProxy.info(this, "Cannot make a test file unreadable."); } }
From source file:ws.ip4u.mediadaemon.FileMover.java
private boolean fixPermissions(File f) { boolean success = f.canWrite() && f.canRead(); if (!f.canWrite()) { success = f.setWritable(true);//from w w w . j av a2 s. com } if (success && !f.canRead()) { success = f.setReadable(true); } return success; }
From source file:net.orpiske.sdm.lib.io.support.ShieldAwareCopier.java
@Override protected void handleFile(File file, int depth, Collection results) throws IOException { File destinationFile = new File(destination, file.getName()); if (!ShieldUtils.isShielded(destinationFile)) { FileUtils.copyFile(file, destinationFile); destinationFile.setExecutable(file.canExecute()); destinationFile.setReadable(file.canRead()); destinationFile.setWritable(file.canWrite()); } else {//from w w w . j a va 2 s .c om System.out.println("Ignoring shielded file " + file.getPath()); } }
From source file:com.thoughtworks.cruise.page.AlreadyOnServerConfigurationTab.java
@com.thoughtworks.gauge.Step("Make snippet with name <snippetName> in command _ repository location <commandRepositoryLocation> unreadable") public void makeSnippetWithNameInCommand_RepositoryLocationUnreadable(String snippetName, String commandRepositoryLocation) throws Exception { String prefix = RuntimePath.getServerRoot() + "/db/command_repository/"; File file = new File(prefix + commandRepositoryLocation, snippetName + ".xml"); file.setReadable(false); }
From source file:com.intel.chimera.utils.NativeCodeLoader.java
/** * Extracts the specified library file to the target folder. * //www . j a v a 2s . c om * @param libFolderForCurrentOS the library in chimera.lib.path. * @param libraryFileName the library name. * @param targetFolder Target folder for the native lib. Use the value of * chimera.tempdir or java.io.tmpdir. * @return the library file. */ private static File extractLibraryFile(String libFolderForCurrentOS, String libraryFileName, String targetFolder) { String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName; // Attach UUID to the native library file to ensure multiple class loaders // can read the libchimera multiple times. String uuid = UUID.randomUUID().toString(); String extractedLibFileName = String.format("chimera-%s-%s-%s", getVersion(), uuid, libraryFileName); File extractedLibFile = new File(targetFolder, extractedLibFileName); InputStream reader = null; try { // Extract a native library file into the target directory reader = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath); FileOutputStream writer = new FileOutputStream(extractedLibFile); try { byte[] buffer = new byte[8192]; int bytesRead; while ((bytesRead = reader.read(buffer)) != -1) { writer.write(buffer, 0, bytesRead); } } finally { // Delete the extracted lib file on JVM exit. extractedLibFile.deleteOnExit(); if (writer != null) { writer.close(); } if (reader != null) { reader.close(); reader = null; } } // Set executable (x) flag to enable Java to load the native library if (!extractedLibFile.setReadable(true) || !extractedLibFile.setExecutable(true) || !extractedLibFile.setWritable(true, true)) { throw new RuntimeException("Invalid path for library path"); } // Check whether the contents are properly copied from the resource folder { InputStream nativeIn = null; InputStream extractedLibIn = null; try { nativeIn = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath); extractedLibIn = new FileInputStream(extractedLibFile); if (!contentsEquals(nativeIn, extractedLibIn)) throw new RuntimeException( String.format("Failed to write a native library file at %s", extractedLibFile)); } finally { if (nativeIn != null) nativeIn.close(); if (extractedLibIn != null) extractedLibIn.close(); } } return new File(targetFolder, extractedLibFileName); } catch (IOException e) { e.printStackTrace(System.err); return null; } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.thoughtworks.go.server.service.lookups.CommandRepositoryDirectoryWalkerTest.java
@Test @DisabledOnOs(OS.WINDOWS)//from ww w .j av a 2s. c om void shouldUpdateServerHealthServiceIfACommandSnippetXMLIsUnReadableAndRemoveItOnceItsReadable() throws IOException { File dirWithUnreadableFile = temporaryFolder.newFolder("dirWithUnreadableFile"); File unreadableFile = new File(dirWithUnreadableFile, "unreadable.xml"); FileUtils.copyFile(xmlFile, unreadableFile); unreadableFile.setReadable(false); walker.getAllCommandSnippets(dirWithUnreadableFile.getPath()); verify(serverHealthService).update(serverHealthWarningMessageWhichContains( "Failed to access command snippet XML file located in Go Server Directory at " + unreadableFile.getPath() + ". Go does not have sufficient permissions to access it.")); unreadableFile.setReadable(true); walker.getAllCommandSnippets(dirWithUnreadableFile.getPath()); verify(serverHealthService, times(2)).update(serverHealthMessageWhichSaysItsOk()); verifyNoMoreInteractions(serverHealthService); }
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 ww.j a 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()); } }