Search in sources :

Example 1 with FaweInputStream

use of com.fastasyncworldedit.core.internal.io.FaweInputStream in project FastAsyncWorldEdit by IntellectualSites.

the class MemoryOptimizedHistory method getBlockIS.

@Override
public FaweInputStream getBlockIS() throws IOException {
    if (ids == null) {
        return null;
    }
    FaweInputStream result = MainUtil.getCompressedIS(new FastByteArraysInputStream(ids));
    readHeader(result);
    return result;
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) FastByteArraysInputStream(com.fastasyncworldedit.core.internal.io.FastByteArraysInputStream)

Example 2 with FaweInputStream

use of com.fastasyncworldedit.core.internal.io.FaweInputStream in project FastAsyncWorldEdit by IntellectualSites.

the class FaweStreamChangeSet method getBiomeIterator.

public Iterator<MutableBiomeChange> getBiomeIterator(final boolean dir) throws IOException {
    final FaweInputStream is = getBiomeIS();
    if (is == null) {
        return Collections.emptyIterator();
    }
    final MutableBiomeChange change = new MutableBiomeChange();
    return new Iterator<MutableBiomeChange>() {

        private MutableBiomeChange last = new MutableBiomeChange();

        public MutableBiomeChange read() {
            try {
                int int1 = is.read();
                if (int1 != -1) {
                    int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + is.read()) << 2;
                    int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read()) << 2;
                    int y = (is.read() - 128) << 2;
                    int from = is.readVarInt();
                    int to = is.readVarInt();
                    change.setBiome(x, y, z, from, to);
                    return change;
                }
            } catch (EOFException ignored) {
            } catch (Exception e) {
                e.printStackTrace();
                e.printStackTrace();
            }
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public boolean hasNext() {
            return last != null || ((last = read()) != null);
        }

        @Override
        public MutableBiomeChange next() {
            MutableBiomeChange tmp = last;
            if (tmp == null) {
                tmp = read();
            }
            last = null;
            return tmp;
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("CANNOT REMOVE");
        }
    };
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) Iterator(java.util.Iterator) EOFException(java.io.EOFException) IOException(java.io.IOException) MutableBiomeChange(com.fastasyncworldedit.core.history.change.MutableBiomeChange) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 3 with FaweInputStream

use of com.fastasyncworldedit.core.internal.io.FaweInputStream in project FastAsyncWorldEdit by IntellectualSites.

the class FaweStreamChangeSet method summarize.

@Override
public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
    int ox = getOriginX();
    int oz = getOriginZ();
    SimpleChangeSetSummary summary = summarizeShallow();
    if (region != null && !region.contains(ox, oz)) {
        return summary;
    }
    try (FaweInputStream fis = getBlockIS()) {
        if (!shallow) {
            int amount = (Settings.settings().HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9;
            MutableFullBlockChange change = new MutableFullBlockChange(null, 0, false);
            for (int i = 0; i < amount; i++) {
                int x = posDel.readX(fis) + ox;
                int y = posDel.readY(fis);
                int z = posDel.readZ(fis) + ox;
                idDel.readCombined(fis, change);
                summary.add(x, z, change.to);
            }
        }
    } catch (EOFException ignored) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return summary;
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) EOFException(java.io.EOFException) MutableFullBlockChange(com.fastasyncworldedit.core.history.change.MutableFullBlockChange) IOException(java.io.IOException)

Example 4 with FaweInputStream

use of com.fastasyncworldedit.core.internal.io.FaweInputStream in project FastAsyncWorldEdit by IntellectualSites.

the class DiskStorageHistory method readHeader.

public IntPair readHeader() {
    int ox = getOriginX();
    int oz = getOriginZ();
    if (ox == 0 && oz == 0 && bdFile.exists()) {
        try (FileInputStream fis = new FileInputStream(bdFile)) {
            final FaweInputStream gis = MainUtil.getCompressedIS(fis);
            // skip mode
            gis.skipFully(1);
            // skip version
            gis.skipFully(1);
            // origin
            ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
            oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
            setOrigin(ox, oz);
            fis.close();
            gis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return new IntPair(ox, oz);
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) IOException(java.io.IOException) IntPair(com.fastasyncworldedit.core.math.IntPair) FileInputStream(java.io.FileInputStream)

Example 5 with FaweInputStream

use of com.fastasyncworldedit.core.internal.io.FaweInputStream in project FastAsyncWorldEdit by IntellectualSites.

the class DiskStorageHistory method getBlockIS.

@Override
public FaweInputStream getBlockIS() throws IOException {
    if (!bdFile.exists()) {
        return null;
    }
    FaweInputStream is = MainUtil.getCompressedIS(new FileInputStream(bdFile));
    readHeader(is);
    return is;
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

FaweInputStream (com.fastasyncworldedit.core.internal.io.FaweInputStream)7 IOException (java.io.IOException)5 EOFException (java.io.EOFException)4 Iterator (java.util.Iterator)3 NoSuchElementException (java.util.NoSuchElementException)3 MutableFullBlockChange (com.fastasyncworldedit.core.history.change.MutableFullBlockChange)2 FileInputStream (java.io.FileInputStream)2 MutableBiomeChange (com.fastasyncworldedit.core.history.change.MutableBiomeChange)1 MutableBlockChange (com.fastasyncworldedit.core.history.change.MutableBlockChange)1 FastByteArraysInputStream (com.fastasyncworldedit.core.internal.io.FastByteArraysInputStream)1 IntPair (com.fastasyncworldedit.core.math.IntPair)1