FastAsyncWorldedit/core/src/main/java/com/boydti/fawe/util/IOUtil.java
Jesse Boyd 6968e66ad8
Various major
Implement virtual worlds
New schematic commands:
//schem show <directory>
//schem delete * - Deletes the files associated with your currently
loaded schematic
//schem move <directory> - Moves your currently loaded schematics to
this directory
//download -> supports downloading multiple schematics at once
2018-04-13 18:40:42 +10:00

57 lines
1.6 KiB
Java

package com.boydti.fawe.util;
import java.io.*;
import java.net.URI;
public final class IOUtil {
public InputStream toInputStream(URI uri) throws IOException {
String scheme = uri.getScheme();
switch (scheme.toLowerCase()) {
case "file":
return new FileInputStream(uri.getPath());
case "http":
case "https":
return uri.toURL().openStream();
default:
return null;
}
}
public static final int readInt(InputStream in) throws IOException {
int ch1 = in.read();
int ch2 = in.read();
int ch3 = in.read();
int ch4 = in.read();
if ((ch1 | ch2 | ch3 | ch4) < 0)
throw new EOFException();
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
}
public static final void writeInt(OutputStream out, int v) throws IOException {
out.write((v >>> 24) & 0xFF);
out.write((v >>> 16) & 0xFF);
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
}
public static void writeVarInt(OutputStream out, int i) throws IOException {
while((i & -128) != 0) {
out.write(i & 127 | 128);
i >>>= 7;
}
out.write(i);
}
public static int readVarInt(InputStream in) throws IOException {
int i = 0;
int offset = 0;
int b;
while ((b = in.read()) > 127) {
i |= (b - 128) << offset;
offset += 7;
}
i |= b << offset;
return i;
}
}