List of usage examples for java.nio.file.attribute UserDefinedFileAttributeView write
int write(String name, ByteBuffer src) throws IOException;
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:/home/docs/users.txt"); UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); view.write("publishable", Charset.defaultCharset().encode("true")); System.out.println("Publishable set"); String name = "publishable"; ByteBuffer buffer = ByteBuffer.allocate(view.size(name)); view.read(name, buffer);/*w w w. j a va2 s. c om*/ buffer.flip(); String value = Charset.defaultCharset().decode(buffer).toString(); System.out.println(value); }
From source file:org.italiangrid.storm.webdav.fs.attrs.DefaultExtendedFileAttributesHelper.java
@Override public void setExtendedFileAttribute(File f, String attributeName, String attributeValue) throws IOException { Assert.notNull(f);/*ww w . jav a2s. co m*/ Assert.hasText(attributeName); UserDefinedFileAttributeView faView = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class); if (faView == null) { throw new IOException("UserDefinedFileAttributeView not supported on file " + f.getAbsolutePath()); } faView.write(attributeName, StandardCharsets.UTF_8.encode(attributeValue)); }
From source file:org.jclouds.kinetic.strategy.internal.KineticStorageStrategyImpl.java
private void writeCommonMetadataAttr(UserDefinedFileAttributeView view, Blob blob) throws IOException { ContentMetadata metadata = blob.getMetadata().getContentMetadata(); writeStringAttributeIfPresent(view, XATTR_CACHE_CONTROL, metadata.getCacheControl()); writeStringAttributeIfPresent(view, XATTR_CONTENT_DISPOSITION, metadata.getContentDisposition()); writeStringAttributeIfPresent(view, XATTR_CONTENT_ENCODING, metadata.getContentEncoding()); writeStringAttributeIfPresent(view, XATTR_CONTENT_LANGUAGE, metadata.getContentLanguage()); writeStringAttributeIfPresent(view, XATTR_CONTENT_TYPE, metadata.getContentType()); Date expires = metadata.getExpires(); if (expires != null) { ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES).putLong(expires.getTime()); buf.flip();/*from ww w. j a v a2s . c o m*/ view.write(XATTR_EXPIRES, buf); } for (Map.Entry<String, String> entry : blob.getMetadata().getUserMetadata().entrySet()) { writeStringAttributeIfPresent(view, XATTR_USER_METADATA_PREFIX + entry.getKey(), entry.getValue()); } }
From source file:org.jclouds.kinetic.strategy.internal.KineticStorageStrategyImpl.java
private String putDirectoryBlob(final String containerName, final Blob blob) throws IOException { String blobKey = blob.getMetadata().getName(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); Long contentLength = metadata.getContentLength(); if (contentLength != null && contentLength != 0) { throw new IllegalArgumentException("Directory blob cannot have content: " + blobKey); }//w ww . j a va 2 s . co m File outputFile = getFileForBlobKey(containerName, blobKey); Path outputPath = outputFile.toPath(); if (!outputFile.isDirectory() && !outputFile.mkdirs()) { throw new IOException("Unable to mkdir: " + outputPath); } UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath); if (view != null) { try { view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(DIRECTORY_MD5)); writeCommonMetadataAttr(view, blob); } catch (IOException e) { logger.debug("xattrs not supported on %s", outputPath); } } else { logger.warn("xattr not supported on %s", blobKey); } return base16().lowerCase().encode(DIRECTORY_MD5); }
From source file:org.jclouds.kinetic.strategy.internal.KineticStorageStrategyImpl.java
/** Write an kinetic attribute, if its value is non-null. */ private static void writeStringAttributeIfPresent(UserDefinedFileAttributeView view, String name, String value) throws IOException { if (value != null) { view.write(name, ByteBuffer.wrap(value.getBytes(StandardCharsets.UTF_8))); }//ww w .j av a 2 s.c om }
From source file:org.ms123.common.git.FileObject.java
public void setString(String key, String value) throws IOException { System.out.println("setString:" + key + "=" + value); Path path = getPath();//from w w w .j a v a 2s. c o m UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); view.write(key, Charset.defaultCharset().encode(value)); }