mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 02:26:00 +01:00
Fix storage performance
This commit is contained in:
parent
e02a43a521
commit
81e8da3b70
@ -172,7 +172,7 @@ private void writeToResponse(CompressedInputStream data, HttpResponse response,
|
||||
byte[] compressedData = byteOut.toByteArray();
|
||||
response.setData(new ByteArrayInputStream(compressedData));
|
||||
} else {
|
||||
response.setData(data.decompress());
|
||||
response.setData(new BufferedInputStream(data.decompress()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,12 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.storage;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import de.bluecolored.bluemap.core.util.DelegateInputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class CompressedInputStream extends FilterInputStream {
|
||||
public class CompressedInputStream extends DelegateInputStream {
|
||||
|
||||
private final Compression compression;
|
||||
|
||||
|
@ -72,10 +72,8 @@ public OutputStream writeMapTile(String mapId, int lod, Vector2i tile) throws IO
|
||||
Path file = getFilePath(mapId, lod, tile);
|
||||
|
||||
OutputStream os = FileHelper.createFilepartOutputStream(file);
|
||||
os = new BufferedOutputStream(os);
|
||||
|
||||
try {
|
||||
os = compression.compress(os);
|
||||
os = new BufferedOutputStream(compression.compress(os));
|
||||
} catch (IOException ex) {
|
||||
os.close();
|
||||
throw ex;
|
||||
@ -92,8 +90,6 @@ public Optional<CompressedInputStream> readMapTile(String mapId, int lod, Vector
|
||||
if (!Files.exists(file)) return Optional.empty();
|
||||
|
||||
InputStream is = Files.newInputStream(file, StandardOpenOption.READ);
|
||||
is = new BufferedInputStream(is);
|
||||
|
||||
return Optional.of(new CompressedInputStream(is, compression));
|
||||
}
|
||||
|
||||
@ -142,9 +138,7 @@ public OutputStream writeMeta(String mapId, String name) throws IOException {
|
||||
Path file = getMetaFilePath(mapId, name);
|
||||
|
||||
OutputStream os = FileHelper.createFilepartOutputStream(file);
|
||||
os = new BufferedOutputStream(os);
|
||||
|
||||
return os;
|
||||
return new BufferedOutputStream(os);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -154,9 +148,7 @@ public Optional<InputStream> readMeta(String mapId, String name) throws IOExcept
|
||||
if (!Files.exists(file)) return Optional.empty();
|
||||
|
||||
InputStream is = Files.newInputStream(file, StandardOpenOption.READ);
|
||||
is = new BufferedInputStream(is);
|
||||
|
||||
return Optional.of(is);
|
||||
return Optional.of(new BufferedInputStream(is));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
public class MySQLStorage extends SQLStorage{
|
||||
public class MySQLStorage extends SQLStorage {
|
||||
|
||||
public MySQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
|
||||
super(MySQLDialect.INSTANCE, config);
|
||||
|
@ -51,7 +51,7 @@ public PostgreSQLStorage(Dialect dialect, SQLStorageSettings config) throws Malf
|
||||
public OutputStream writeMapTile(String mapId, int lod, Vector2i tile) throws IOException {
|
||||
Compression compression = lod == 0 ? this.hiresCompression : Compression.NONE;
|
||||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
||||
return new OnCloseOutputStream(compression.compress(byteOut), () -> {
|
||||
return new OnCloseOutputStream(new BufferedOutputStream(compression.compress(byteOut)), () -> {
|
||||
int mapFK = getMapFK(mapId);
|
||||
int tileCompressionFK = getMapTileCompressionFK(compression);
|
||||
|
||||
|
@ -108,7 +108,7 @@ public OutputStream writeMapTile(String mapId, int lod, Vector2i tile) throws IO
|
||||
Compression compression = lod == 0 ? this.hiresCompression : Compression.NONE;
|
||||
|
||||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
||||
return new OnCloseOutputStream(compression.compress(byteOut), () -> {
|
||||
return new OnCloseOutputStream(new BufferedOutputStream(compression.compress(byteOut)), () -> {
|
||||
int mapFK = getMapFK(mapId);
|
||||
int tileCompressionFK = getMapTileCompressionFK(compression);
|
||||
|
||||
|
@ -0,0 +1,82 @@
|
||||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class DelegateInputStream extends InputStream {
|
||||
|
||||
protected final InputStream in;
|
||||
|
||||
public DelegateInputStream(InputStream in) {
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return in.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte @NotNull [] b) throws IOException {
|
||||
return in.read(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte @NotNull [] b, int off, int len) throws IOException {
|
||||
return in.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readAllBytes() throws IOException {
|
||||
return in.readAllBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readNBytes(int len) throws IOException {
|
||||
return in.readNBytes(len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readNBytes(byte[] b, int off, int len) throws IOException {
|
||||
return in.readNBytes(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
return in.skip(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return in.available();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return in.markSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mark(int readlimit) {
|
||||
in.mark(readlimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
in.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long transferTo(OutputStream out) throws IOException {
|
||||
return in.transferTo(out);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class DelegateOutputStream extends OutputStream {
|
||||
|
||||
protected final OutputStream out;
|
||||
|
||||
public DelegateOutputStream(OutputStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte @NotNull [] b) throws IOException {
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte @NotNull [] b, int off, int len) throws IOException {
|
||||
out.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
@ -24,11 +24,10 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class OnCloseInputStream extends FilterInputStream {
|
||||
public class OnCloseInputStream extends DelegateInputStream {
|
||||
|
||||
private final AutoCloseable onClose;
|
||||
|
||||
@ -42,7 +41,7 @@ public void close() throws IOException {
|
||||
IOException ioExcetion = null;
|
||||
|
||||
try {
|
||||
in.close();
|
||||
super.close();
|
||||
} catch (IOException ex) {
|
||||
ioExcetion = ex;
|
||||
}
|
||||
|
@ -24,11 +24,10 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class OnCloseOutputStream extends FilterOutputStream {
|
||||
public class OnCloseOutputStream extends DelegateOutputStream {
|
||||
|
||||
private final AutoCloseable onClose;
|
||||
|
||||
@ -42,7 +41,7 @@ public void close() throws IOException {
|
||||
IOException ioExcetion = null;
|
||||
|
||||
try {
|
||||
out.close();
|
||||
super.close();
|
||||
} catch (IOException ex) {
|
||||
ioExcetion = ex;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user