-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExt2File.java
63 lines (55 loc) · 2.17 KB
/
Ext2File.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.*;
import java.util.Scanner;
/**
*This class provides a way to readBytes bytes in a Randomly Accessed File, either from a given offset
*or from the current file pointer
*@author Petros Soutzis, 2017-19
*/
public class Ext2File
{
private RandomAccessFile raf;
/**
*Constructor of Ext2File class. Will readBytes the ext2fs image and return the bytes that were readBytes.
*@param vol is the Volume that the Ext2File will readBytes bytes from.
*/
public Ext2File(Volume vol) {
raf = vol.getRandomAccessFile();
}
/**
*Reads at most length bytes starting at byte offset startByte from start of file.
*Byte 0 is the first byte in the file.
*StartByte must be such that, 0 less or equal than, startByte less than file.size or an exception should be raised.
*@param startByte the offset from which the file will start reading from
*@param length the size that the byte-array will have
*@throws IOException is thrown when an error happens during the reading of the RAF
*@return the byte array that the random access file readBytes from the volume
*/
byte[] readBytes(long startByte, long length) throws IOException{
byte[] data = new byte[(int) length];
raf.seek(startByte);
raf.readFully(data);
return data;
}
/**
* @return The name (or pathname) of the disk to read (filesystem image).
*/
static String getFileSystemName(){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the name of the disk to read (or the full path if not in the same folder).");
System.out.print("FS Name: ");
return scanner.nextLine();
}
// /**
// *Reads at most length bytes, starting from the current file pointer.
// *@param length the size that the byte-array will have
// *@throws IOException e
// *@return the byte array that the random access file readBytes from the volume
// */
// public byte[] readBytes(long length) throws IOException {
// byte[] data = new byte[(int)length];
// raf.seek(raf.getFilePointer());
// raf.readFully(data);
//
// return data;
// }
}