use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method updateFile.
public RepositoryFile updateFile(RepositoryFile file, IRepositoryFileData data, String versionMessage) {
File f = new File(file.getId().toString());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f, false);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
} catch (IOException e) {
throw new UnifiedRepositoryException(e);
} finally {
IOUtils.closeQuietly(fos);
}
return getFile(file.getPath());
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class RepositoryFileReader method getEncoding.
protected static String getEncoding(String path) throws FileNotFoundException {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile file = (new RepositoryFileInputStream(path)).getFile();
SimpleRepositoryFileData fileData = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
return fileData.getEncoding();
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFile.
public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
FileOutputStream fos = null;
File f = new File(fileNameWithPath);
try {
f.createNewFile();
fos = new FileOutputStream(f);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} catch (IOException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} finally {
IOUtils.closeQuietly(fos);
}
return internalGetFile(f);
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method getData.
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> T getData(Serializable fileId, Serializable versionId, Class<T> dataClass) {
File f = new File(fileId.toString());
T data = null;
try {
if (SimpleRepositoryFileData.class.getName().equals(dataClass.getName())) {
data = (T) new SimpleRepositoryFileData(new FileInputStream(f), "UTF-8", "text/plain");
} else if (NodeRepositoryFileData.class.getName().equals(dataClass.getName())) {
throw new UnsupportedOperationException("This operation is not support by this repository");
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
}
return data;
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class SimpleRepositoryFileDataTransformer method fromContentNode.
/**
* {@inheritDoc}
*/
public SimpleRepositoryFileData fromContentNode(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node fileNode) throws RepositoryException {
String encoding = null;
Node resourceNode = fileNode.getNode(pentahoJcrConstants.getJCR_CONTENT());
if (resourceNode.hasProperty(pentahoJcrConstants.getJCR_ENCODING())) {
encoding = resourceNode.getProperty(pentahoJcrConstants.getJCR_ENCODING()).getString();
}
InputStream data = resourceNode.getProperty(pentahoJcrConstants.getJCR_DATA()).getBinary().getStream();
String mimeType = resourceNode.getProperty(pentahoJcrConstants.getJCR_MIMETYPE()).getString();
return new SimpleRepositoryFileData(data, encoding, mimeType);
}
Aggregations