public void load(final InputStream in) { load(in, true); }
public void store(final OutputStream out) { store(out, true); }
@Test public void testState() throws IOException { final File fcontent = File.createTempFile("foo", "bar"); final Properties properties = new Properties(); final Date dt = new Date(); properties.put("int", 10453); properties.put("long", 1000000L); properties.put("date", dt); final OutputStream out = new FileOutputStream(fcontent); properties.store(out); final Properties loadProperties = new Properties(); final InputStream in = new FileInputStream(fcontent); loadProperties.load(in); assertNotNull(properties.get("int")); assertNotNull(properties.get("long")); assertNotNull(properties.get("date")); assertEquals(10453, properties.get("int")); assertEquals(1000000L, properties.get("long")); assertEquals(dt, properties.get("date")); }
protected void loadDotFile(final Path path) { final Properties content = new Properties(); content.load(newInputStream(dot(path))); if (path instanceof AttrHolder) { ((AttrHolder) path).getAttrStorage().loadContent(content); } }
public void load(final InputStream in, boolean closeOnFinish) { final XStream xstream = XStreamUtils.createTrustingXStream(); final Properties temp = new Properties(); try { xstream.fromXML(in, temp); } catch (final XStreamException ex) { if (ex.getCause() != null) { if (!ex.getCause().getMessage().equals("input contained no data")) { throw ex; } } } for (final Map.Entry<String, Object> entry : temp.entrySet()) { if (entry.getValue() != null) { put(entry.getKey(), entry.getValue()); } } temp.clear(); if (closeOnFinish) { try { in.close(); } catch (IOException e) { } } } }
boolean hasContent = false; if (attrs != null && attrs.length > 0) { final Properties properties = new Properties(); properties.put(attr.name(), attr.value()); properties.store(out); } catch (final Exception e) { throw new IOException(e);
@Test public void testEmptyState() throws IOException { final File fcontent = File.createTempFile("foo2", "bar"); final Properties loadProperties = new Properties(); final InputStream in = new FileInputStream(fcontent); loadProperties.load(in); assertEquals(0, loadProperties.size()); }
@Override public Map<String, Object> readAttributes(final Path path, final String attributes) throws UnsupportedOperationException, NoSuchFileException, IllegalArgumentException, IOException, SecurityException { checkNotNull("path", path); checkNotEmpty("attributes", attributes); final Properties original = new Properties(Files.readAttributes(path, attributes)); if (attributes.equals("*") && exists(dot(path))) { boolean isAttrHolder = path instanceof AttrHolder; if (isAttrHolder && ((AttrHolder) path).getAttrStorage().getContent().size() > 0) { return ((AttrHolder) path).getAttrStorage().getAllContent(); } final Properties content = new Properties(); content.load(newInputStream(dot(path))); content.putAll(original); if (isAttrHolder) { ((AttrHolder) path).getAttrStorage().loadContent(content); } return content; } return original; }
@Test public void testNullValues() throws IOException { final Map<String, Object> original = new HashMap<String, Object>(); original.put("key1", "value1"); original.put("key2", null); final Properties properties = new Properties(original); assertEquals(1, properties.size()); assertTrue(properties.containsKey("key1")); assertEquals("value1", properties.get("key1")); assertFalse(properties.containsKey("key2")); } }
private synchronized Properties buildProperties(boolean includesNonSerializable) { final Properties properties = new Properties(content); for (final Map.Entry<String, AttributeView> view : viewsNameIndex.entrySet()) { if (includesNonSerializable || view.getValue() instanceof ExtendedAttributeView && ((ExtendedAttributeView) view.getValue()).isSerializable()) { final ExtendedAttributeView extendedView = (ExtendedAttributeView) view.getValue(); for (final Map.Entry<String, Object> attr : extendedView.readAllAttributes().entrySet()) { properties.put(attr.getKey(), attr.getValue()); } } } return properties; } }
public Properties(final Map<String, Object> original) { for (Map.Entry<String, Object> e : original.entrySet()) { if (e.getValue() != null) { put(e.getKey(), e.getValue()); } } }
@Override public void clear() { viewsNameIndex.clear(); viewsTypeIndex.clear(); content.clear(); }
protected Path internalCreateDirectory(final Path dir, final boolean skipAlreadyExistsException, final FileAttribute<?>... attrs) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull("dir", dir); FileAttribute<?>[] allAttrs = attrs; try { Files.createDirectory(dir, attrs); } catch (final FileAlreadyExistsException ex) { final Properties properties = new Properties(); if (exists(dot(dir))) { properties.load(newInputStream(dot(dir))); } allAttrs = consolidate(properties, attrs); if (!skipAlreadyExistsException) { throw ex; } } buildDotFile(dir, newOutputStream(dot(dir)), allAttrs); return dir; }
public void load(final InputStream in, boolean closeOnFinish) { final XStream xstream = XStreamUtils.createTrustingXStream(); final Properties temp = new Properties(); try { xstream.fromXML(in, temp); } catch (final XStreamException ex) { if (ex.getCause() != null) { if (!ex.getCause().getMessage().equals("input contained no data")) { throw ex; } } } for (final Map.Entry<String, Object> entry : temp.entrySet()) { if (entry.getValue() != null) { put(entry.getKey(), entry.getValue()); } } temp.clear(); if (closeOnFinish) { try { in.close(); } catch (IOException e) { } } } }
boolean hasContent = false; if (attrs != null && attrs.length > 0) { final Properties properties = new Properties(); properties.put(attr.name(), attr.value()); properties.store(out); } catch (final Exception e) { throw new IOException(e);
private synchronized Properties buildProperties(boolean includesNonSerializable) { final Properties properties = new Properties(content); for (final Map.Entry<String, AttributeView> view : viewsNameIndex.entrySet()) { if (includesNonSerializable || view.getValue() instanceof ExtendedAttributeView && ((ExtendedAttributeView) view.getValue()).isSerializable()) { final ExtendedAttributeView extendedView = (ExtendedAttributeView) view.getValue(); for (final Map.Entry<String, Object> attr : extendedView.readAllAttributes().entrySet()) { properties.put(attr.getKey(), attr.getValue()); } } } return properties; } }
public Properties(final Map<String, Object> original) { for (Map.Entry<String, Object> e : original.entrySet()) { if (e.getValue() != null) { put(e.getKey(), e.getValue()); } } }
@Override public void clear() { viewsNameIndex.clear(); viewsTypeIndex.clear(); content.clear(); }
@Override public SeekableByteChannel newByteChannel(final Path path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull("path", path); final Properties properties = new Properties(); if (exists(dot(path))) { properties.load(newInputStream(dot(path))); } final FileAttribute<?>[] allAttrs = consolidate(properties, attrs); final SeekableByteChannel result = Files.newByteChannel(path, buildOptions(options), allAttrs); if (isFileScheme(path)) { buildDotFile(path, newOutputStream(dot(path)), allAttrs); } return result; }