Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cosyverif
Services
service adt2amas
Commits
707331a9
Commit
707331a9
authored
Dec 16, 2020
by
Jaime Arias
Browse files
feature: compress output file in a zip file
parent
a2bcf7eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/cosyverif/service/adt2amas/MinimalScheduling.java
View file @
707331a9
...
...
@@ -3,16 +3,23 @@ package org.cosyverif.service.adt2amas;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.FilenameFilter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.apache.commons.compress.archivers.zip.Zip64ExtendedInformationExtraField
;
import
org.apache.commons.exec.CommandLine
;
import
org.cosyverif.alligator.service.AnnotatedService.Task
;
import
org.cosyverif.Configuration
;
import
org.cosyverif.alligator.service.BinaryService
;
import
org.cosyverif.alligator.service.Parameter.Direction
;
import
org.cosyverif.alligator.service.annotation.Example
;
...
...
@@ -52,6 +59,9 @@ public class MinimalScheduling extends BinaryService {
@Parameter
(
name
=
"Scheduling Table"
,
help
=
"Formatted table with the minimal scheduling"
,
direction
=
Direction
.
OUT
,
contenttype
=
"plain/text"
)
private
File
outputTables
=
null
;
@Parameter
(
name
=
"Outputs files"
,
help
=
"Compress file containing all the generated files"
,
direction
=
Direction
.
OUT
,
contenttype
=
"application/zip"
)
private
File
outputZip
=
null
;
@Launch
public
Task
executeBinary
()
throws
IOException
{
parser
=
GrmlParser
.
create
(
modelParameter
);
...
...
@@ -72,6 +82,7 @@ public class MinimalScheduling extends BinaryService {
public
void
fallback
(
String
line
){
try
{
outputParameter
=
formatResult
(
model
);
outputZip
=
compressResults
();
outputTables
=
getTables
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
@@ -139,6 +150,41 @@ public class MinimalScheduling extends BinaryService {
return
s
.
toString
();
}
private
File
compressResults
()
throws
IOException
{
FileOutputStream
fos
=
null
;
ZipOutputStream
zos
=
null
;
File
zf
=
null
;
try
{
File
directory
=
new
File
(
baseDirectory
().
getAbsolutePath
());
zf
=
new
File
(
directory
.
getAbsolutePath
()
+
"/results.zip"
);
fos
=
new
FileOutputStream
(
zf
);
zos
=
new
ZipOutputStream
(
fos
);
File
[]
files
=
directory
.
listFiles
(
new
FilenameFilter
()
{
public
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
endsWith
(
".txt"
)
||
name
.
endsWith
(
".tex"
);
}
});
for
(
File
file
:
files
)
{
zos
.
putNextEntry
(
new
ZipEntry
(
file
.
getName
()));
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
file
.
getAbsolutePath
()));
zos
.
write
(
bytes
,
0
,
bytes
.
length
);
zos
.
closeEntry
();
}
}
finally
{
if
(
zos
!=
null
)
zos
.
close
();
if
(
fos
!=
null
)
fos
.
close
();
}
return
zf
;
}
private
File
getTables
()
throws
IOException
{
File
fileOutput
=
null
;
BufferedWriter
bw
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment