Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DARIAH-DE Aggregator Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DARIAH-DE
DARIAH-DE Aggregator Services
Commits
68a92ee3
Commit
68a92ee3
authored
11 years ago
by
Thorsten Vitt
Browse files
Options
Downloads
Patches
Plain Diff
Made CorpusBasedExporter's buffer configurable
parent
67769c21
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
src/main/java/info/textgrid/services/aggregator/CorpusBasedExporter.java
+59
-7
59 additions, 7 deletions
...nfo/textgrid/services/aggregator/CorpusBasedExporter.java
with
59 additions
and
7 deletions
src/main/java/info/textgrid/services/aggregator/CorpusBasedExporter.java
+
59
−
7
View file @
68a92ee3
...
...
@@ -8,8 +8,12 @@
import
info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault
;
import
info.textgrid.services.aggregator.teicorpus.TEICorpusSerializer
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.text.MessageFormat
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
@@ -22,19 +26,61 @@
import
com.google.common.io.ByteStreams
;
import
com.google.common.io.FileBackedOutputStream
;
import
com.google.common.io.Files
;
import
com.google.common.io.InputSupplier
;
public
abstract
class
CorpusBasedExporter
extends
AbstractExporter
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
CorpusBasedExporter
.
class
.
getCanonicalName
());
protected
boolean
readStylesheetPI
=
false
;
private
InputSupplier
<
InputStream
>
sourceBuffer
=
null
;
private
InputSupplier
<?
extends
InputStream
>
sourceBuffer
=
null
;
private
IBufferFactory
bufferFactory
=
new
FBBAOSBufferFactory
();
public
CorpusBasedExporter
(
final
ITextGridRep
repository
,
final
Request
request
,
final
String
uriList
)
{
super
(
repository
,
request
,
uriList
);
}
public
static
interface
IBufferFactory
{
public
OutputStream
getBufferSink
();
public
InputSupplier
<?
extends
InputStream
>
getBufferContents
();
}
public
static
final
class
FBBAOSBufferFactory
implements
IBufferFactory
{
private
FileBackedOutputStream
sink
;
@Override
public
OutputStream
getBufferSink
()
{
this
.
sink
=
new
FileBackedOutputStream
(
1024
*
1024
,
true
);
return
sink
;
}
@Override
public
InputSupplier
<
InputStream
>
getBufferContents
()
{
return
sink
.
getSupplier
();
}
}
public
static
final
class
FileBufferFactory
implements
IBufferFactory
{
private
final
File
file
;
private
FileOutputStream
sink
;
public
FileBufferFactory
(
final
File
file
)
throws
FileNotFoundException
{
this
.
file
=
file
;
this
.
sink
=
new
FileOutputStream
(
file
);
}
@Override
public
InputSupplier
<?
extends
InputStream
>
getBufferContents
()
{
return
Files
.
newInputStreamSupplier
(
file
);
}
@Override
public
OutputStream
getBufferSink
()
{
return
sink
;
}
}
/**
* Loads a source for the given document.
*
...
...
@@ -83,17 +129,15 @@ protected Source loadSource(final boolean bufferRequired)
||
sourceType
==
SourceType
.
BASKET
)
{
final
TEICorpusSerializer
corpusSerializer
=
new
TEICorpusSerializer
(
getRootObjects
(),
false
,
getSid
().
orNull
());
final
FileBackedOutputStream
corpusBuffer
=
new
FileBackedOutputStream
(
1024
*
1024
,
true
);
final
OutputStream
corpusBuffer
=
getBufferFactory
().
getBufferSink
();
corpusSerializer
.
write
(
corpusBuffer
);
corpusBuffer
.
close
();
sourceBuffer
=
corpusBuffer
.
getSupplier
();
sourceBuffer
=
getBufferFactory
().
getBufferContents
();
source
=
new
StreamSource
(
sourceBuffer
.
getInput
());
}
else
if
(
sourceType
==
SourceType
.
XML
&&
bufferRequired
)
{
final
FileBackedOutputStream
xmlBuffer
=
new
FileBackedOutputStream
(
1024
*
1024
,
true
);
final
OutputStream
xmlBuffer
=
getBufferFactory
().
getBufferSink
();
ByteStreams
.
copy
(
getContentSimple
(),
xmlBuffer
);
sourceBuffer
=
xml
Buffer
.
getSupplier
();
sourceBuffer
=
get
Buffer
Factory
().
getBufferContents
();
source
=
new
StreamSource
(
sourceBuffer
.
getInput
());
}
else
{
source
=
new
StreamSource
(
getContentSimple
().
getInput
(),
...
...
@@ -106,4 +150,12 @@ protected Source loadSource(final boolean bufferRequired)
return
source
;
}
private
IBufferFactory
getBufferFactory
()
{
return
bufferFactory
;
}
protected
void
setBufferFactory
(
final
IBufferFactory
bufferFactory
)
{
this
.
bufferFactory
=
bufferFactory
;
}
}
\ No newline at end of file
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