Skip to content

Commit 5544039

Browse files
committed
make file separator java compliant
1 parent 59260b6 commit 5544039

File tree

62 files changed

+591
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+591
-357
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ Here's a few really simple examples.
8686
CDBuilder builder = new CDBuilder();
8787
builder.useJoliet = true;
8888
builder.volumeIdentifier = "A_SAMPLE_DISK";
89-
builder.addFile("Folder\\Hello.txt", "Hello World!".getBytes(Charset.forName("ASCII")));
90-
builder.build("C:\\temp\\sample.iso");
89+
builder.addFile("folder/Hello.txt", "Hello World!".getBytes(Charset.forName("ASCII")));
90+
builder.build("/tmp/sample.iso");
9191
```
9292

9393
You can add files as byte arrays (shown above), as files from the Windows filesystem, or as a Stream. By using a different form of Build, you can get a Stream to the ISO file, rather than writing it to the Windows filesystem.
@@ -96,9 +96,9 @@ You can add files as byte arrays (shown above), as files from the Windows filesy
9696
### How to extract a file from an ISO:
9797

9898
```Java
99-
try (FileStream isoStream = File.open("C:\\temp\\sample.iso")) {
99+
try (FileStream isoStream = File.open("/tmp/sample.iso")) {
100100
CDReader cd = new CDReader(isoStream, true);
101-
Stream fileStream = cd.openFile("Folder\\Hello.txt", FileMode.Open);
101+
Stream fileStream = cd.openFile("folder/Hello.txt", FileMode.Open);
102102
// Use fileStream...
103103
}
104104
```
@@ -109,11 +109,11 @@ You can also browse through the directory hierarchy, starting at cd.Root.
109109

110110
```Java
111111
long diskSize = 30 * 1024 * 1024; // 30MB
112-
try (Stream vhdStream = File.create("C:\\TEMP\\mydisk.vhd")) {
112+
try (Stream vhdStream = File.create("/tmp/mydisk.vhd")) {
113113
Disk disk = Disk.initializeDynamic(vhdStream, diskSize);
114114
BiosPartitionTable.initialize(disk, WellKnownPartitionType.WindowsFat);
115115
try (FatFileSystem fs = FatFileSystem.formatPartition(disk, 0, null)) {
116-
fs.createDirectory("TestDir\\CHILD");
116+
fs.createDirectory("TestDir/CHILD");
117117
// do other things with the file system...
118118
}
119119
}
@@ -165,7 +165,7 @@ Automated CI builds are available on [Github](https://github.com/umjammer/vavi-n
165165
* compile by jdk8
166166
* ~~https://github.com/AssafTzurEl/discUtils/commit/3853944811a16d6220dcb6e8d408561e05569e43~~
167167
* img ... https://github.com/hessu/bchunk
168-
* file separator
168+
* ~~file separator~~
169169
* pc98 partition (wip)
170170
* d88 floppy disk
171171
* qcow2

src/main/java/discUtils/bootConfig/DiscUtilsRegistryStorage.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131

3232

3333
public class DiscUtilsRegistryStorage extends BaseStorage {
34+
35+
private static final String FS = java.io.File.separator;
36+
3437
private static final UUID EMPTY = new UUID(0, 0);
3538

36-
private static final String ElementsPathTemplate = "Objects\\%s\\Elements";
39+
private static final String ElementsPathTemplate = "Objects" + FS + "%s" + FS + "Elements";
3740

38-
private static final String ElementPathTemplate = "Objects\\%s\\Elements\\%8X";
41+
private static final String ElementPathTemplate = "Objects" + FS + "%s" + FS + "Elements" + FS + "%8X";
3942

40-
private static final String ObjectTypePathTemplate = "Objects\\%s\\Description";
43+
private static final String ObjectTypePathTemplate = "Objects" + FS + "%s" + FS + "Description";
4144

4245
private static final String ObjectsPath = "Objects";
4346

src/main/java/discUtils/btrfs/Symlink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public Symlink(DirEntry dirEntry, Context context) {
3737
public String getTargetPath() {
3838
IBuffer content = getFileContent();
3939
byte[] data = StreamUtilities.readExact(content, 0, (int) content.getCapacity());
40-
return new String(data, 0, data.length, StandardCharsets.UTF_8).replace('/', '\\');
40+
return new String(data, 0, data.length, StandardCharsets.UTF_8).replace('/', java.io.File.separatorChar);
4141
}
4242
}

src/main/java/discUtils/core/DiscDirectoryInfo.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package discUtils.core;
2424

25+
import java.io.File;
2526
import java.io.IOException;
2627
import java.util.List;
2728
import java.util.stream.Collectors;
@@ -61,7 +62,7 @@ public boolean exists() {
6162
* Gets the full path of the directory.
6263
*/
6364
public String getFullName() {
64-
return super.getFullName() + "\\";
65+
return super.getFullName() + File.separator;
6566
}
6667

6768
/**

src/main/java/discUtils/core/DiscFileSystemInfo.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package discUtils.core;
2424

25+
import java.io.File;
2526
import java.io.IOException;
2627
import java.util.EnumSet;
2728

@@ -35,13 +36,16 @@
3536
* {@link DiscDirectoryInfo} objects.
3637
*/
3738
public class DiscFileSystemInfo {
39+
40+
private static final String FS = File.separator;
41+
3842
public DiscFileSystemInfo(DiscFileSystem fileSystem, String path) {
3943
if (path == null) {
4044
throw new NullPointerException("path");
4145
}
4246

4347
_fileSystem = fileSystem;
44-
_path = path.replaceAll(StringUtilities.escapeForRegex("(^\\*|\\*$)"), "");
48+
_path = path.replaceAll(StringUtilities.escapeForRegex("(^" + FS + "*|" + FS + "*$)"), "");
4549
//Debug.println(_path);
4650
}
4751

src/main/java/discUtils/core/FileLocator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package discUtils.core;
2424

25+
import java.io.File;
2526
import java.util.function.BiConsumer;
2627

2728
import discUtils.core.internal.Utilities;
@@ -74,7 +75,7 @@ public String makeRelativePath(FileLocator fileLocator, String path) {
7475
return null;
7576
}
7677

77-
String ourFullPath = getFullPath("") + "\\";
78+
String ourFullPath = getFullPath("") + File.separator;
7879
String otherFullPath = fileLocator.getFullPath(path);
7980

8081
return Utilities.makeRelativePath(otherFullPath, ourFullPath);

src/main/java/discUtils/core/FileTransport.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package discUtils.core;
2424

25+
import java.io.File;
2526
import java.net.URI;
2627
import java.nio.file.Files;
2728
import java.nio.file.Paths;
@@ -45,10 +46,10 @@ public boolean isRawDisk() {
4546
}
4647

4748
public void connect(URI uri, String username, String password) {
48-
_path = uri.getPath().replace("/", "\\");
49+
_path = uri.getPath().replace("/", File.separator);
4950
_extraInfo = uri.getFragment();
5051
String path = Utilities.getDirectoryFromPath(_path);
51-
if (path == null || !Files.exists(Paths.get(path.replace("\\", "/")))) {
52+
if (path == null || !Files.exists(Paths.get(path))) {
5253
throw new dotnet4j.io.FileNotFoundException(String.format("No such file '%s'", uri));
5354
}
5455
}
@@ -58,7 +59,7 @@ public VirtualDisk openDisk(FileAccess access) {
5859
}
5960

6061
public FileLocator getFileLocator() {
61-
return new LocalFileLocator(Utilities.getDirectoryFromPath(_path) + "\\");
62+
return new LocalFileLocator(Utilities.getDirectoryFromPath(_path) + File.separator);
6263
}
6364

6465
public String getFileName() {

0 commit comments

Comments
 (0)