Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<version>3.2.1</version>
</dependency>
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/bdv/model/DataSet.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package bdv.model;

import org.eclipse.jetty.util.log.Log;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;

/**
* DataSet class holds SPIM dataset information
*/
public class DataSet
{
private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger( DataSet.class );

private static Path dataSetListPath;
/**
* DataSet Context name of this {@link bdv.server.CellHandler} is serving.
Expand All @@ -31,6 +37,8 @@ public class DataSet
private String thumbnailUrl;
private String datasetUrl;

public static int numBackups = 5;

/**
* Instantiates a new DataSet
*
Expand Down Expand Up @@ -198,6 +206,34 @@ public static void storeDataSet( ArrayList< DataSet > list ) throws IOException
{
if ( dataSetListPath != null )
{
// fist make a copy of the XML and save it to not loose it
if ( Files.exists( dataSetListPath ) )
{
int maxExistingBackup = 0;
for ( int i = 1; i < numBackups; ++i )
if ( Files.exists( Paths.get( dataSetListPath + "~" + i ) ) )
maxExistingBackup = i;
else
break;

// copy the backups
try
{
for ( int i = maxExistingBackup; i >= 1; --i )
Files.copy( Paths.get( dataSetListPath + "~" + i ),
Paths.get( dataSetListPath + "~" + ( i + 1 ) ),
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING );

Files.copy( dataSetListPath, Paths.get( dataSetListPath + "~" + 1 ),
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING );
}
catch ( final IOException e )
{
LOG.warn( "Could not save backup of data list file: " + e );
e.printStackTrace();
}
}

BufferedWriter writer = Files.newBufferedWriter( dataSetListPath, StandardCharsets.UTF_8 );
for ( DataSet ds : list )
{
Expand Down
Loading