我正在尝试为 jackrabbit 进行上传,但 zip 文件下载已损坏
maven依赖:
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr2dav</artifactId>
<version>${jackrabit.version}</version>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
<version>${javax.jcr.version}</version>
</dependency>
上传代码:
isRollback = compactaFile( IOUtils.toInputStream( dmls.get( 1 ) ), rollbackFileNamesql , rollbackFileName);
getThreadParam().jackRabbitUtil.upload( path,
rollbackFileName,
isRollback );
private InputStream compactaFile(InputStream dml, String fileName, String tmpFileName) throws Exception{
byte[] buffer = new byte[1024];
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(baos);
ZipEntry ze= new ZipEntry(fileName );
zout.putNextEntry(ze);
int len;
while ((len = dml.read(buffer)) > 0) {
zout.write(buffer, 0, len);
}
dml.close();
zout.closeEntry();
zout.finish();
zout.close();
baos.flush();
baos.close();
ByteArrayInputStream ios = new ByteArrayInputStream(baos.toByteArray());
return ios;
}catch(Exception e){
throw e;
}
}
public synchronized void upload( String filePath, String fileName,InputStream content ) throws Exception {
if ( StringUtils.isBlank( filePath ) ) {
throw new Exception( "O caminho para upload do arquivo nao foi informado." );
}
if ( StringUtils.isBlank( fileName ) ) {
throw new Exception( "O nome do arquivo para upload nao foi informado." );
}
if ( content == null ) {
throw new Exception( "O conteudo do arquivo para upload nao foi informado." );
}
Session session = getSession();
Node root = session.getRootNode();
String[] folders = filePath.split( File.separator );
Node uploadNode = null;
VersionManager versionManager = session.getWorkspace().getVersionManager();
String path = "";
for ( String folder : folders ) {
if ( !StringUtils.isBlank( folder ) ) {
if ( !root.hasNode( folder ) ) {
root.addNode( folder, "nt:folder" );
uploadNode = root.getNode( folder );
uploadNode.addMixin( "mix:versionable" );
session.save();
}
uploadNode = root.getNode( folder );
path += File.separator + uploadNode.getName();
versionManager.checkout( path );
root = uploadNode;
}
}
if ( uploadNode != null && !uploadNode.hasNode( fileName ) ) {
Node nodefile = uploadNode.addNode( fileName, "nt:file" );
nodefile.addMixin( "mix:versionable" );
final Node resource = nodefile.addNode( "jcr:content", "nt:resource" );
Binary value = session.getValueFactory().createBinary( content );
resource.setProperty( "jcr:data", value );
session.save();
versionManager.checkin( path );
}
}
它将zip文件上传到jackrabbit,但是当我下载文件时,它已损坏