package com.develop.ss.config;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
public class IndexPathBean {
private final String propFilePath = "index.properties";
private String nextIndexPath;
private String curIndexPath;
private String nextIndex;
private Properties props;
private void getPaths() throws IOException
{
File f = new File(propFilePath);
if (!f.exists()) {
throw new IOException("properties path " + propFilePath + " does not exist");
}
props = new Properties();
props.load(new FileInputStream(propFilePath));
String indexRelativePath = props.getProperty("index.next");
if (indexRelativePath == null) {
throw new IllegalArgumentException("indexRelativePath not set in " + propFilePath);
}
nextIndex = Integer.toString(1 - Integer.parseInt(indexRelativePath));
curIndexPath = props.getProperty("index.fullpath") + indexRelativePath;
nextIndexPath = props.getProperty("index.fullpath") + nextIndex;
}
public String getFlippedIndexPath() throws IOException
{
getPaths();
return nextIndexPath;
}
public String getIndexPath() throws IOException {
getPaths();
return curIndexPath;
}
public void flipIndexPath() throws IOException
{
props.setProperty("index.next", nextIndex);
props.store(new FileOutputStream(propFilePath), "");
}
}
|