当前位置: 首页>>代码示例>>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;未经允许,请勿转载。