Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
f0a35274
Commit
f0a35274
authored
11 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
SP-724, BIS-428: refactoring ZipBasedHierarchicalContent.
SVN: 29460
parent
0a94bf98
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openbis-common/source/java/ch/systemsx/cisd/openbis/common/io/hierarchical_content/ZipBasedHierarchicalContent.java
+122
-105
122 additions, 105 deletions
.../io/hierarchical_content/ZipBasedHierarchicalContent.java
with
122 additions
and
105 deletions
openbis-common/source/java/ch/systemsx/cisd/openbis/common/io/hierarchical_content/ZipBasedHierarchicalContent.java
+
122
−
105
View file @
f0a35274
...
@@ -222,6 +222,126 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
...
@@ -222,6 +222,126 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
}
}
}
}
private
static
final
class
HDF5ContainerNode
extends
HDF5ContainerBasedHierarchicalContentNode
{
private
final
BasicZipFile
zipFile
;
private
final
String
relativePath
;
private
final
ZipEntry
zipEntry
;
private
boolean
loaded
;
private
HDF5ContainerNode
(
IHierarchicalContent
root
,
File
hdf5ContainerFile
,
BasicZipFile
zipFile
,
String
relativePath
,
ZipEntry
zipEntry
)
{
super
(
root
,
hdf5ContainerFile
);
this
.
zipFile
=
zipFile
;
this
.
relativePath
=
relativePath
;
this
.
zipEntry
=
zipEntry
;
}
private
synchronized
void
lazyLoad
()
{
if
(
loaded
==
false
)
{
copyZipEntryToFile
(
file
);
loaded
=
true
;
}
}
private
void
copyZipEntryToFile
(
File
tempFile
)
{
InputStream
in
=
null
;
FileOutputStream
out
=
null
;
BufferedOutputStream
bufferedOut
=
null
;
try
{
in
=
zipFile
.
getInputStream
(
zipEntry
);
out
=
new
FileOutputStream
(
tempFile
);
bufferedOut
=
new
BufferedOutputStream
(
out
);
IOUtils
.
copy
(
in
,
bufferedOut
);
}
catch
(
Exception
ex
)
{
throw
CheckedExceptionTunnel
.
wrapIfNecessary
(
ex
);
}
finally
{
IOUtils
.
closeQuietly
(
in
);
IOUtils
.
closeQuietly
(
bufferedOut
);
}
}
@Override
public
String
doGetRelativePath
()
{
return
relativePath
;
}
@Override
public
String
getName
()
{
return
extractName
(
relativePath
);
}
@Override
public
InputStream
doGetInputStream
()
{
lazyLoad
();
return
super
.
doGetInputStream
();
}
@Override
protected
IHDF5ContainerReader
createReader
()
{
lazyLoad
();
return
super
.
createReader
();
}
@Override
public
long
getLastModified
()
{
return
zipEntry
.
getTime
();
}
@Override
public
long
doGetFileLength
()
{
return
zipEntry
.
getSize
();
}
@Override
protected
int
doGetChecksumCRC32
()
{
return
(
int
)
zipEntry
.
getCrc
();
}
@Override
public
File
getFile
()
{
lazyLoad
();
return
super
.
getFile
();
}
@Override
public
boolean
isChecksumCRC32Precalculated
()
{
return
true
;
}
@Override
public
File
tryGetFile
()
{
lazyLoad
();
return
super
.
tryGetFile
();
}
@Override
public
IRandomAccessFile
doGetFileContent
()
{
lazyLoad
();
return
super
.
doGetFileContent
();
}
}
private
static
final
class
NodeManager
private
static
final
class
NodeManager
{
{
private
final
Map
<
String
,
ZipContainerNode
>
containerNodes
=
new
HashMap
<
String
,
ZipContainerNode
>();
private
final
Map
<
String
,
ZipContainerNode
>
containerNodes
=
new
HashMap
<
String
,
ZipContainerNode
>();
...
@@ -254,90 +374,8 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
...
@@ -254,90 +374,8 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
{
{
File
tempFile
=
File
.
createTempFile
(
TEMP_FILE_PREFIX
,
extractName
(
relativePath
),
TEMP_FOLDER
);
File
tempFile
=
File
.
createTempFile
(
TEMP_FILE_PREFIX
,
extractName
(
relativePath
),
TEMP_FOLDER
);
unzippedFiles
.
add
(
tempFile
);
unzippedFiles
.
add
(
tempFile
);
IHierarchicalContentNode
contentNode
=
new
HDF5ContainerBasedHierarchicalContentNode
(
hierarchicalContent
,
tempFile
)
IHierarchicalContentNode
contentNode
=
{
new
HDF5ContainerNode
(
hierarchicalContent
,
tempFile
,
zipFile
,
relativePath
,
zipEntry
);
private
boolean
loaded
;
private
synchronized
void
lazyLoad
()
{
if
(
loaded
==
false
)
{
copyZipEntryToFile
(
zipFile
,
zipEntry
,
file
);
loaded
=
true
;
}
}
@Override
public
String
doGetRelativePath
()
{
return
relativePath
;
}
@Override
public
String
getName
()
{
return
extractName
(
relativePath
);
}
@Override
public
InputStream
doGetInputStream
()
{
lazyLoad
();
return
super
.
doGetInputStream
();
}
@Override
protected
IHDF5ContainerReader
createReader
()
{
lazyLoad
();
return
super
.
createReader
();
}
@Override
public
long
getLastModified
()
{
return
zipEntry
.
getTime
();
}
@Override
public
long
doGetFileLength
()
{
return
zipEntry
.
getSize
();
}
@Override
protected
int
doGetChecksumCRC32
()
{
return
(
int
)
zipEntry
.
getCrc
();
}
@Override
public
File
getFile
()
{
lazyLoad
();
return
super
.
getFile
();
}
@Override
public
boolean
isChecksumCRC32Precalculated
()
{
return
true
;
}
@Override
public
File
tryGetFile
()
{
lazyLoad
();
return
super
.
tryGetFile
();
}
@Override
public
IRandomAccessFile
doGetFileContent
()
{
lazyLoad
();
return
super
.
doGetFileContent
();
}
};
linkNode
(
contentNode
,
relativePath
);
linkNode
(
contentNode
,
relativePath
);
}
catch
(
Exception
ex
)
}
catch
(
Exception
ex
)
{
{
...
@@ -350,27 +388,6 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
...
@@ -350,27 +388,6 @@ public class ZipBasedHierarchicalContent extends AbstractHierarchicalContent
}
}
}
}
private
void
copyZipEntryToFile
(
BasicZipFile
zipFile
,
ZipEntry
zipEntry
,
File
tempFile
)
{
InputStream
in
=
null
;
FileOutputStream
out
=
null
;
BufferedOutputStream
bufferedOut
=
null
;
try
{
in
=
zipFile
.
getInputStream
(
zipEntry
);
out
=
new
FileOutputStream
(
tempFile
);
bufferedOut
=
new
BufferedOutputStream
(
out
);
IOUtils
.
copy
(
in
,
bufferedOut
);
}
catch
(
Exception
ex
)
{
throw
CheckedExceptionTunnel
.
wrapIfNecessary
(
ex
);
}
finally
{
IOUtils
.
closeQuietly
(
in
);
IOUtils
.
closeQuietly
(
bufferedOut
);
}
}
private
void
linkNode
(
IHierarchicalContentNode
contentNode
,
String
relativePath
)
private
void
linkNode
(
IHierarchicalContentNode
contentNode
,
String
relativePath
)
{
{
allNodes
.
put
(
relativePath
,
contentNode
);
allNodes
.
put
(
relativePath
,
contentNode
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment