parent.mkdirs();
}
if (!parent.canWrite()) {
String parentPath = parent.getAbsolutePath();
String msg = JcrI18n.fileConnectorCannotWriteToDirectory.text(getSourceName(), getClass(), parentPath);
throw new DocumentStoreException(id, msg);
}
String primaryType = reader.getPrimaryTypeName();
Map<Name, Property> properties = reader.getProperties();
ExtraProperties extraProperties = extraPropertiesFor(id, false);
extraProperties.addAll(properties).except(JCR_PRIMARY_TYPE, JCR_CREATED, JCR_LAST_MODIFIED, JCR_DATA);
try {
if (NT_FILE.equals(primaryType)) {
file.createNewFile();
} else if (NT_FOLDER.equals(primaryType)) {
file.mkdirs();
} else if (isContentNode(id)) {
Property content = properties.get(JcrLexicon.DATA);
BinaryValue binary = factories().getBinaryFactory().create(content.getFirstValue());
OutputStream ostream = new BufferedOutputStream(new FileOutputStream(file));
IoUtil.write(binary.getStream(), ostream);
if (!NT_RESOURCE.equals(primaryType)) {
// This is the "jcr:content" child, but the primary type is non-standard so record it as an extra property
extraProperties.add(properties.get(JcrLexicon.PRIMARY_TYPE));
}
}
extraProperties.save();
} catch (RepositoryException | IOException e) {
throw new DocumentStoreException(id, e);
}
}