-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from itesla/improve_iidm_caserepo
changes iidm file extension convention to xiidm (xml is still OK) and…
- Loading branch information
Showing
12 changed files
with
135 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...mport-export-api/src/main/java/eu/itesla_project/iidm/datasource/Bzip2FileDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) 2016, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package eu.itesla_project.iidm.datasource; | ||
|
||
import java.io.*; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Objects; | ||
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; | ||
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; | ||
|
||
|
||
/** | ||
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it> | ||
*/ | ||
public class Bzip2FileDataSource implements DataSource { | ||
|
||
private final Path directory; | ||
|
||
private final String baseName; | ||
|
||
private final DataSourceObserver observer; | ||
|
||
public Bzip2FileDataSource(Path directory, String baseName, DataSourceObserver observer) { | ||
this.directory = Objects.requireNonNull(directory); | ||
this.baseName = Objects.requireNonNull(baseName); | ||
this.observer = observer; | ||
} | ||
|
||
public Bzip2FileDataSource(Path directory, String baseName) { | ||
this(directory, baseName, null); | ||
} | ||
|
||
@Override | ||
public String getBaseName() { | ||
return baseName; | ||
} | ||
|
||
private Path getPath(String suffix, String ext) { | ||
return directory.resolve(DataSourceUtil.getFileName(baseName, suffix, ext + ".bz2")); | ||
} | ||
|
||
@Override | ||
public OutputStream newOutputStream(String suffix, String ext, boolean append) throws IOException { | ||
Path path = getPath(suffix, ext); | ||
OutputStream os = new BZip2CompressorOutputStream(new BufferedOutputStream(Files.newOutputStream(path, append ? StandardOpenOption.APPEND : StandardOpenOption.CREATE))); | ||
return observer != null ? new ObservableOutputStream(os, path.toString(), observer) : os; | ||
} | ||
|
||
@Override | ||
public boolean exists(String suffix, String ext) { | ||
Path path = getPath(suffix, ext); | ||
return Files.isRegularFile(path); | ||
} | ||
|
||
@Override | ||
public boolean exists(String fileName) throws IOException { | ||
Path path = directory.resolve(fileName + ".bz2"); | ||
return Files.isRegularFile(path); | ||
} | ||
|
||
@Override | ||
public InputStream newInputStream(String suffix, String ext) throws IOException { | ||
return new BZip2CompressorInputStream(new BufferedInputStream(Files.newInputStream(getPath(suffix, ext)))); | ||
} | ||
|
||
@Override | ||
public InputStream newInputStream(String fileName) throws IOException { | ||
return new BZip2CompressorInputStream(new BufferedInputStream(Files.newInputStream(directory.resolve(fileName + ".bz2")))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters