當前位置: 首頁>>代碼示例>>Java>>正文


Java File.setWritable方法代碼示例

本文整理匯總了Java中java.io.File.setWritable方法的典型用法代碼示例。如果您正苦於以下問題:Java File.setWritable方法的具體用法?Java File.setWritable怎麽用?Java File.setWritable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.File的用法示例。


在下文中一共展示了File.setWritable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUnwritableRemoveContainerPipeline

import java.io.File; //導入方法依賴的package包/類
@Test
@Category(NeedsRunner.class)
public void testUnwritableRemoveContainerPipeline() throws Exception {

    final Map<String, String> dataConfiguration = singletonMap("repository",
            getClass().getResource("/dataDirectory2").toURI().toString());

    final File root = new File(getClass().getResource("/dataDirectory2").toURI());

    assumeTrue(root.setReadOnly());

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(CONTAINER_KV))
        .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), false)));

    PAssert.that(pCollection).empty();

    pipeline.run();
    root.setWritable(true);
}
 
開發者ID:trellis-ldp-archive,項目名稱:trellis-rosid-file-streaming,代碼行數:21,代碼來源:BeamProcessorTest.java

示例2: testUnwritableAddContainerPipeline

import java.io.File; //導入方法依賴的package包/類
@Test
@Category(NeedsRunner.class)
public void testUnwritableAddContainerPipeline() throws Exception {

    final Map<String, String> dataConfiguration = singletonMap("repository",
            getClass().getResource("/dataDirectory2").toURI().toString());

    final File root = new File(getClass().getResource("/dataDirectory2").toURI());

    assumeTrue(root.setReadOnly());

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(CONTAINER_KV))
        .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), true)));

    PAssert.that(pCollection).empty();

    pipeline.run();
    root.setWritable(true);
}
 
開發者ID:trellis-ldp-archive,項目名稱:trellis-rosid-file-streaming,代碼行數:21,代碼來源:BeamProcessorTest.java

示例3: recursiveDelete

import java.io.File; //導入方法依賴的package包/類
public static boolean recursiveDelete(String fileName) {
    File file = new File(fileName);
    if (file.exists()) {
        //check if the file is a directory
        if (file.isDirectory()) {
            if ((file.list()).length > 0) {
                for(String s:file.list()){
                    //call deletion of file individually
                    recursiveDelete(fileName + System.getProperty("file.separator") + s);
                }
            }
        }

        if (!file.setWritable(true)) {
            LOGGER.error("File is not writable");
        }

        boolean result = file.delete();
        return result;
    } else {
        return false;
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:24,代碼來源:FileUtil.java

示例4: changeFilePermisson4Win

import java.io.File; //導入方法依賴的package包/類
/**
 * Change the permission of the file to --Readable, Writable, Executable--
 * 
 * @param fileName
 */
public static void changeFilePermisson4Win(String fileName) {

    File file = new File(fileName);
    if (!file.exists()) {
        return;
    }

    if (!file.canRead()) {
        file.setReadable(true);
    }

    if (!file.canWrite()) {
        file.setWritable(true);
    }

    if (!file.canExecute()) {
        file.setExecutable(true);
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:25,代碼來源:UpgradeUtil.java

示例5: initBundled

import java.io.File; //導入方法依賴的package包/類
private void initBundled() throws IOException {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
    tmpDir.setReadable(true);
    tmpDir.setWritable(true);
    tmpDir.setExecutable(true);
    tmpDir.mkdirs();

    String solcPath = "/native/" + getOS() + "/solc/";
    InputStream is = getClass().getResourceAsStream(solcPath + "file.list");
    Scanner scanner = new Scanner(is);
    while (scanner.hasNext()) {
        String s = scanner.next();
        File targetFile = new File(tmpDir, s);
        InputStream fis = getClass().getResourceAsStream(solcPath + s);
        Files.copy(fis, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        if (solc == null) {
            // first file in the list denotes executable
            solc = targetFile;
            solc.setExecutable(true);
        }
        targetFile.deleteOnExit();
    }
    tmpDir.deleteOnExit();
}
 
開發者ID:web3j,項目名稱:web3j-maven-plugin,代碼行數:25,代碼來源:SolC.java

示例6: upload

import java.io.File; //導入方法依賴的package包/類
public void upload() throws IOException {
    
	try (InputStream input = file.getInputstream()) {
        Date date = new Date();
        long datetime = date.getTime();

		//Files.copy(input, new File("/Users/darrenw/Downloads/PrimeTest/Uploads/"+ datetime + file.getFileName()).toPath())
	  //  File fileper = new File("/Users/darrenw/Downloads/PrimeTest/Uploads/"+ datetime + file.getFileName());
        Files.copy(input, new File("/home/ubuntu/Uploads/"+ datetime + file.getFileName()).toPath());
	    File fileper = new File("/home/ubuntu/Uploads/"+ datetime + file.getFileName());
	    fileper.setReadable(true, false);
	    fileper.setWritable(true, false);
	  //  setSshkeypath("/Users/darrenw/Downloads/PrimeTest/Uploads/"+ datetime + file.getFileName());
 	  setSshkeypath("/home/ubuntu/Uploads/"+ datetime + file.getFileName());

	    System.out.println(sshkeypath.toString());
	}     
}
 
開發者ID:dice-project,項目名稱:DICE-Fault-Injection-GUI,代碼行數:19,代碼來源:BandwidthView.java

示例7: writePrivateKey

import java.io.File; //導入方法依賴的package包/類
/**
 * writes private key
 *
 * @param key String
 */
protected String writePrivateKey(String key) {
  String uuid = UUID.randomUUID().toString();
  String fileName = config.getDataDir() + "/" + uuid;
  try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(fileName))) {
    bw.write(key);
    bw.close();
    File f = new File(fileName);
    f.setExecutable(false, false);
    f.setReadable(false, false);
    f.setWritable(false, false);
    f.setReadable(true, true);
    f.setWritable(true, true);
    logger.debug("file: " + fileName);
  } catch (IOException e) {
    logger.error("could not write file: " + fileName + " msg:"
        + e.getMessage());
  }
  return fileName;
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:25,代碼來源:AbstractOrderExecutor.java

示例8: uploadFile

import java.io.File; //導入方法依賴的package包/類
/** 上傳文件處理(支持批量) */
public static List<String> uploadFile(HttpServletRequest request) {
    CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
            request.getSession().getServletContext());
    List<String> fileNames = InstanceUtil.newArrayList();
    if (multipartResolver.isMultipart(request)) {
        MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
        String pathDir = getUploadDir(request);
        File dirFile = new File(pathDir);
        if (!dirFile.isDirectory()) {
            dirFile.mkdirs();
        }
        for (Iterator<String> iterator = multiRequest.getFileNames(); iterator.hasNext();) {
            String key = iterator.next();
            MultipartFile multipartFile = multiRequest.getFile(key);
            if (multipartFile != null) {
                String name = multipartFile.getOriginalFilename();
                String uuid = UUID.randomUUID().toString();
                String postFix = name.substring(name.lastIndexOf(".")).toLowerCase();
                String fileName = uuid + postFix;
                String filePath = pathDir + File.separator + fileName;
                File file = new File(filePath);
                file.setWritable(true, false);
                try {
                    multipartFile.transferTo(file);
                    fileNames.add(fileName);
                } catch (Exception e) {
                    logger.error(name + "保存失敗", e);
                }
            }
        }
    }
    return fileNames;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:35,代碼來源:UploadUtil.java

示例9: getFuzzerDirectory

import java.io.File; //導入方法依賴的package包/類
public static File getFuzzerDirectory() {
	File storageDir = new File(Environment.getExternalStorageDirectory(),
			"evoFuzzDumps/");
	if (!storageDir.exists() && !storageDir.mkdirs())
		Log.e(SharedClassesSettings.TAG, "Could not create communication directory for watchdog: " + storageDir);
	storageDir.setWritable(true, false);
	Log.i(SharedClassesSettings.TAG, "Communication directory for watchdog: " + storageDir);
	return storageDir;
}
 
開發者ID:srasthofer,項目名稱:FuzzDroid,代碼行數:10,代碼來源:FileBasedTracingUtils.java

示例10: startExtension

import java.io.File; //導入方法依賴的package包/類
/**
 * Start extension by communicating with osquery core and starting thrift
 * server
 * 
 * @param name
 *            name of extension
 * @param version
 *            version of extension
 * @param sdkVersion
 *            version of the osquery SDK used to build this extension
 * @param minSdkVersion
 *            minimum version of the osquery SDK that you can use
 * @throws IOException
 * @throws ExtensionException
 */
public void startExtension(String name, String version, String sdkVersion, String minSdkVersion)
		throws IOException, ExtensionException {
	ExtensionManager.Client client = new ClientManager(EXTENSION_SOCKET).getClient();
	InternalExtensionInfo info = new InternalExtensionInfo(name, version, sdkVersion, minSdkVersion);
	try {
		ExtensionStatus status = client.registerExtension(info, registry);
		if (status.getCode() == 0) {
			this.uuid = status.uuid;
			Processor<PluginManager> processor = new Processor<PluginManager>(this);
			String serverSocketPath = EXTENSION_SOCKET + "." + String.valueOf(uuid);
			File socketFile = new File(serverSocketPath);
			if (socketFile.exists()) {
				socketFile.delete();
			}
			AFUNIXServerSocket socket = AFUNIXServerSocket.bindOn(new AFUNIXSocketAddress(socketFile));
			socketFile.setExecutable(true, false);
			socketFile.setWritable(true, false);
			socketFile.setReadable(true, false);
			TServerSocket transport = new TServerSocket(socket);
			TTransportFactory transportFactory = new TTransportFactory();
			TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
			TServer server = new TSimpleServer(new Args(transport).processor(processor)
					.transportFactory(transportFactory).protocolFactory(protocolFactory));

			// Run it
			System.out.println("Starting the server...");
			server.serve();
		} else {
			throw new ExtensionException(1, status.getMessage(), uuid);
		}
	} catch (TException e) {
		throw new ExtensionException(1, "Could not connect to socket", uuid);
	}
}
 
開發者ID:melastmohican,項目名稱:osquery-java,代碼行數:50,代碼來源:PluginManager.java

示例11: testReadOnlySnapshotDir

import java.io.File; //導入方法依賴的package包/類
/**
 * Tests that the ZooKeeper server will fail to start if the
 * snapshot directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlySnapshotDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the snapshot directory read only
    File snapDir = new File(main.dataDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    snapDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    snapDir.setWritable(true);

    main.deleteDirs();
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:40,代碼來源:ZooKeeperServerMainTest.java

示例12: testSecretInPropertiesFile

import java.io.File; //導入方法依賴的package包/類
@Test
public void testSecretInPropertiesFile() throws Exception {
    final String secretValue = "secretValue";

    final SecretHandler secretHandler = args -> {
        args[1] = secretValue;
        return args;
    };

    final class TestFlags {
        @Flag(name = "secret")
        private String secret;
    }

    final File propertiesFile = File.createTempFile("test", "properties");
    propertiesFile.setWritable(true);
    final FileOutputStream fio = new FileOutputStream(propertiesFile);
    final String properties = "secret=valueToBeExchanged\n";
    fio.write(properties.getBytes());
    fio.close();

    final TestFlags testFlags = new TestFlags();
    new Flags(new SecretHandler[]{secretHandler})
            .loadOpts(testFlags)
            .parse(new String[]{"--properties-file", propertiesFile.getAbsolutePath()});

    assertEquals(secretValue, testFlags.secret);
}
 
開發者ID:secondbase,項目名稱:secondbase,代碼行數:29,代碼來源:FlagsTest.java

示例13: testWriteErrors

import java.io.File; //導入方法依賴的package包/類
@Test
public void testWriteErrors() throws Exception {
    final File file = new File(getClass().getResource("/readonly/resource.rdfp").toURI());
    assumeTrue(file.setWritable(false));
    assertFalse(RDFPatch.write(file, empty(), empty(), now()));
    file.setWritable(true);
}
 
開發者ID:trellis-ldp-archive,項目名稱:trellis-rosid-file,代碼行數:8,代碼來源:RDFPatchTest.java

示例14: testReadOnlySnapshotDir

import java.io.File; //導入方法依賴的package包/類
/**
 * Tests that the ZooKeeper server will fail to start if the
 * snapshot directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlySnapshotDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true, null);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the snapshot directory read only
    File snapDir = new File(main.dataDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    snapDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir, null);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    snapDir.setWritable(true);

    main.deleteDirs();
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:40,代碼來源:ZooKeeperServerMainTest.java

示例15: uploadFile

import java.io.File; //導入方法依賴的package包/類
/**
    * 上傳文件處理(支持批量)
    * @param request
    * @param pathDir 上傳文件保存路徑
    * @return
    * @throws IllegalStateException
    * @throws IOException
    */
public static List<String> uploadFile(HttpServletRequest request,String pathDir) throws IllegalStateException, IOException {
	CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
			request.getSession().getServletContext());
	List<String> fileNames = new ArrayList<String>();
	if (multipartResolver.isMultipart(request)) {
		MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
		Iterator<String> iterator = multiRequest.getFileNames();
		if(pathDir==null|| pathDir.equals("")){
			pathDir = request.getSession().getServletContext().getRealPath(uploadFileDir + DateUtils.currentTime());
		}
           File dirFile = new File(pathDir);
           if (!dirFile.isDirectory()) {
               dirFile.mkdirs();
           }
		while (iterator.hasNext()) {
			String key = iterator.next();
			MultipartFile multipartFile = multiRequest.getFile(key);
			if (multipartFile != null) {
				String uuid = UUID.randomUUID().toString().replace("-", "");
				String name = multipartFile.getOriginalFilename();
				int lastIndexOf = name.lastIndexOf(".");
				String postFix="";
				if(lastIndexOf!=-1){
					postFix = name.substring(lastIndexOf).toLowerCase();
				}
				String fileName = uuid + postFix;
				String filePath = pathDir + File.separator + fileName;
				File file = new File(filePath);
				file.setWritable(true, false);

				multipartFile.transferTo(file);
				fileNames.add(file.getAbsolutePath());
			}
		}
	}
	return fileNames;
}
 
開發者ID:mumucommon,項目名稱:mumu-core,代碼行數:46,代碼來源:UploadUtil.java


注:本文中的java.io.File.setWritable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。