minor changes for allowing coffee manager access from cooja
This commit is contained in:
parent
8d9f8e3a17
commit
b4f3cce790
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: CoffeeConfiguration.java,v 1.3 2009/08/11 14:42:58 nvt-se Exp $
|
||||
* $Id: CoffeeConfiguration.java,v 1.4 2009/08/11 17:03:59 fros4943 Exp $
|
||||
*
|
||||
* @author Nicolas Tsiftes
|
||||
*
|
||||
|
@ -39,6 +39,8 @@ package se.sics.coffee;
|
|||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
import se.sics.coffee.CoffeeFS.CoffeeException;
|
||||
|
||||
public class CoffeeConfiguration {
|
||||
public static final int FD_SET_SIZE = 256;
|
||||
public static final int MAX_OPEN_FILES = 256;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: CoffeeFS.java,v 1.4 2009/08/10 12:51:52 nvt-se Exp $
|
||||
* $Id: CoffeeFS.java,v 1.5 2009/08/11 17:03:59 fros4943 Exp $
|
||||
*
|
||||
* @author Nicolas Tsiftes
|
||||
*
|
||||
|
@ -40,18 +40,6 @@ import java.io.*;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
class CoffeeException extends RuntimeException {
|
||||
public CoffeeException(String message) {
|
||||
super("Coffee error: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
class CoffeeFileException extends RuntimeException {
|
||||
public CoffeeFileException(String message) {
|
||||
super("Coffee file error: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public class CoffeeFS {
|
||||
private CoffeeImage image;
|
||||
private CoffeeConfiguration conf;
|
||||
|
@ -142,9 +130,12 @@ public class CoffeeFS {
|
|||
}
|
||||
|
||||
public CoffeeFile insertFile(String filename) throws IOException {
|
||||
return insertFile(new File(filename));
|
||||
}
|
||||
|
||||
public CoffeeFile insertFile(File file) throws IOException {
|
||||
CoffeeFile coffeeFile;
|
||||
try {
|
||||
File file = new File(filename);
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
int allocatePages = pageCount(file.length());
|
||||
int start = findFreeExtent(allocatePages);
|
||||
|
@ -153,7 +144,7 @@ public class CoffeeFS {
|
|||
return null;
|
||||
}
|
||||
CoffeeHeader header = new CoffeeHeader(this, start);
|
||||
header.setName(filename);
|
||||
header.setName(file.getName());
|
||||
header.setReservedSize(allocatePages);
|
||||
header.allocate();
|
||||
coffeeFile = new CoffeeFile(this, header);
|
||||
|
@ -179,13 +170,31 @@ public class CoffeeFS {
|
|||
}
|
||||
|
||||
public boolean extractFile(String filename) throws IOException {
|
||||
CoffeeFile file = files.get(filename);
|
||||
return extractFile(filename, new File(filename));
|
||||
}
|
||||
|
||||
public boolean extractFile(String fileInCoffee, File fileOnDisk) throws IOException {
|
||||
CoffeeFile file = files.get(fileInCoffee);
|
||||
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
file.saveContents(filename);
|
||||
file.saveContents(fileOnDisk);
|
||||
return true;
|
||||
}
|
||||
|
||||
static class CoffeeException extends RuntimeException {
|
||||
public CoffeeException(String message) {
|
||||
super("Coffee error: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
static class CoffeeFileException extends RuntimeException {
|
||||
public CoffeeFileException(String message) {
|
||||
super("Coffee file error: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: CoffeeFile.java,v 1.5 2009/08/11 14:42:58 nvt-se Exp $
|
||||
* $Id: CoffeeFile.java,v 1.6 2009/08/11 17:03:59 fros4943 Exp $
|
||||
*
|
||||
* @author Nicolas Tsiftes
|
||||
*
|
||||
|
@ -94,14 +94,14 @@ public class CoffeeFile {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveContents(String filename) throws IOException {
|
||||
public void saveContents(File file) throws IOException {
|
||||
int startOffset = header.getPage() *
|
||||
coffeeFS.getConfiguration().pageSize +
|
||||
header.rawLength();
|
||||
int i;
|
||||
byte[] bytes;
|
||||
|
||||
FileOutputStream fOut = new FileOutputStream(filename);
|
||||
FileOutputStream fOut = new FileOutputStream(file);
|
||||
|
||||
if (microLog != null) {
|
||||
for (i = 0; i < microLog.getLogRecords(); i++) {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: CoffeeImage.java,v 1.1 2009/08/04 10:36:53 nvt-se Exp $
|
||||
* $Id: CoffeeImage.java,v 1.2 2009/08/11 17:03:59 fros4943 Exp $
|
||||
*
|
||||
* @author Nicolas Tsiftes
|
||||
*
|
||||
|
@ -38,7 +38,7 @@ package se.sics.coffee;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
interface CoffeeImage {
|
||||
public interface CoffeeImage {
|
||||
CoffeeConfiguration getConfiguration();
|
||||
void read(byte[] bytes, int size, int offset) throws IOException;
|
||||
void write(byte[] bytes, int size, int offset) throws IOException;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: CoffeeManager.java,v 1.3 2009/08/10 12:51:52 nvt-se Exp $
|
||||
* $Id: CoffeeManager.java,v 1.4 2009/08/11 17:03:59 fros4943 Exp $
|
||||
*
|
||||
* @author Nicolas Tsiftes
|
||||
*
|
||||
|
@ -144,7 +144,7 @@ public class CoffeeManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void printStatistics(CoffeeFS coffeeFS) {
|
||||
public static void printStatistics(CoffeeFS coffeeFS) {
|
||||
int bytesWritten = 0;
|
||||
int bytesReserved = 0;
|
||||
int fileCount = 0;
|
||||
|
@ -177,7 +177,7 @@ public class CoffeeManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void printFiles(Map<String, CoffeeFile> files) {
|
||||
public static void printFiles(Map<String, CoffeeFile> files) {
|
||||
try {
|
||||
Iterator<Map.Entry<String, CoffeeFile>> iterator = files.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
|
Loading…
Reference in a new issue