Search in sources :

Example 1 with FastByteArrayInputStream

use of it.unimi.dsi.fastutil.io.FastByteArrayInputStream in project invesdwin-context by invesdwin.

the class ADelegateDailyDownloadListRequest method call.

@Override
public final List<? extends E> call() throws Exception {
    try {
        final String content = newDailyDownloadCache().downloadString(getDownloadFileName(), new Callable<String>() {

            @Override
            public String call() throws Exception {
                try (PooledFastByteArrayOutputStream out = PooledFastByteArrayOutputStream.newInstance()) {
                    try (IBeanTableWriter<E> writer = newWriter(out.asNonClosing())) {
                        writer.write(download());
                    }
                    return new String(out.toByteArray());
                }
            }
        }, getNow());
        if (Strings.isBlank(content)) {
            throw new RetryLaterRuntimeException("Empty result for request: " + getDownloadFileName());
        }
        final ICloseableIterator<E> reader = newReader(new FastByteArrayInputStream(content.getBytes()));
        final List<E> list = Lists.toListWithoutHasNext(reader);
        Assertions.checkNotEmpty(list, "%s", getDownloadFileName());
        return list;
    } catch (final Throwable t) {
        DailyDownloadCache.delete(getDownloadFileName());
        throw Throwables.propagate(t);
    }
}
Also used : FastByteArrayInputStream(it.unimi.dsi.fastutil.io.FastByteArrayInputStream) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) PooledFastByteArrayOutputStream(de.invesdwin.util.streams.pool.PooledFastByteArrayOutputStream) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) IOException(java.io.IOException) IBeanTableWriter(de.invesdwin.context.integration.csv.writer.IBeanTableWriter)

Example 2 with FastByteArrayInputStream

use of it.unimi.dsi.fastutil.io.FastByteArrayInputStream in project PowerNukkitX by BlocklyNukkit.

the class PositionTrackingDBServerBroadcastPacket method decode.

@Override
public void decode() {
    action = ACTIONS[getByte()];
    trackingId = getVarInt();
    try (FastByteArrayInputStream inputStream = new FastByteArrayInputStream(get())) {
        tag = NBTIO.readNetworkCompressed(inputStream);
    } catch (IOException e) {
        throw new EncoderException(e);
    }
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) FastByteArrayInputStream(it.unimi.dsi.fastutil.io.FastByteArrayInputStream) IOException(java.io.IOException)

Example 3 with FastByteArrayInputStream

use of it.unimi.dsi.fastutil.io.FastByteArrayInputStream in project PowerNukkitX by PowerNukkitX.

the class Binary method readMetadata.

public static EntityMetadata readMetadata(byte[] payload) {
    BinaryStream stream = new BinaryStream();
    stream.setBuffer(payload);
    long count = stream.getUnsignedVarInt();
    EntityMetadata m = new EntityMetadata();
    for (int i = 0; i < count; i++) {
        int key = (int) stream.getUnsignedVarInt();
        int type = (int) stream.getUnsignedVarInt();
        EntityData value = null;
        switch(type) {
            case Entity.DATA_TYPE_BYTE:
                value = new ByteEntityData(key, stream.getByte());
                break;
            case Entity.DATA_TYPE_SHORT:
                value = new ShortEntityData(key, stream.getLShort());
                break;
            case Entity.DATA_TYPE_INT:
                value = new IntEntityData(key, stream.getVarInt());
                break;
            case Entity.DATA_TYPE_FLOAT:
                value = new FloatEntityData(key, stream.getLFloat());
                break;
            case Entity.DATA_TYPE_STRING:
                value = new StringEntityData(key, stream.getString());
                break;
            case Entity.DATA_TYPE_NBT:
                int offset = stream.getOffset();
                FastByteArrayInputStream fbais = new FastByteArrayInputStream(stream.get());
                try {
                    CompoundTag tag = NBTIO.read(fbais, ByteOrder.LITTLE_ENDIAN, true);
                    value = new NBTEntityData(key, tag);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
                stream.setOffset(offset + (int) fbais.position());
                break;
            case Entity.DATA_TYPE_POS:
                BlockVector3 v3 = stream.getSignedBlockPosition();
                value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
                break;
            case Entity.DATA_TYPE_LONG:
                value = new LongEntityData(key, stream.getVarLong());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                value = new Vector3fEntityData(key, stream.getVector3f());
                break;
        }
        if (value != null)
            m.put(value);
    }
    return m;
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BlockVector3(cn.nukkit.math.BlockVector3) FastByteArrayInputStream(it.unimi.dsi.fastutil.io.FastByteArrayInputStream) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 4 with FastByteArrayInputStream

use of it.unimi.dsi.fastutil.io.FastByteArrayInputStream in project PowerNukkitX by BlocklyNukkit.

the class Binary method readMetadata.

public static EntityMetadata readMetadata(byte[] payload) {
    BinaryStream stream = new BinaryStream();
    stream.setBuffer(payload);
    long count = stream.getUnsignedVarInt();
    EntityMetadata m = new EntityMetadata();
    for (int i = 0; i < count; i++) {
        int key = (int) stream.getUnsignedVarInt();
        int type = (int) stream.getUnsignedVarInt();
        EntityData value = null;
        switch(type) {
            case Entity.DATA_TYPE_BYTE:
                value = new ByteEntityData(key, stream.getByte());
                break;
            case Entity.DATA_TYPE_SHORT:
                value = new ShortEntityData(key, stream.getLShort());
                break;
            case Entity.DATA_TYPE_INT:
                value = new IntEntityData(key, stream.getVarInt());
                break;
            case Entity.DATA_TYPE_FLOAT:
                value = new FloatEntityData(key, stream.getLFloat());
                break;
            case Entity.DATA_TYPE_STRING:
                value = new StringEntityData(key, stream.getString());
                break;
            case Entity.DATA_TYPE_NBT:
                int offset = stream.getOffset();
                FastByteArrayInputStream fbais = new FastByteArrayInputStream(stream.get());
                try {
                    CompoundTag tag = NBTIO.read(fbais, ByteOrder.LITTLE_ENDIAN, true);
                    value = new NBTEntityData(key, tag);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
                stream.setOffset(offset + (int) fbais.position());
                break;
            case Entity.DATA_TYPE_POS:
                BlockVector3 v3 = stream.getSignedBlockPosition();
                value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
                break;
            case Entity.DATA_TYPE_LONG:
                value = new LongEntityData(key, stream.getVarLong());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                value = new Vector3fEntityData(key, stream.getVector3f());
                break;
        }
        if (value != null)
            m.put(value);
    }
    return m;
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BlockVector3(cn.nukkit.math.BlockVector3) FastByteArrayInputStream(it.unimi.dsi.fastutil.io.FastByteArrayInputStream) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 5 with FastByteArrayInputStream

use of it.unimi.dsi.fastutil.io.FastByteArrayInputStream in project invesdwin-context by invesdwin.

the class ClasspathResourceProcessor method processDirectory.

/**
 * we also need to process directories, since if they are missing in newly generated jars, classpath scanning by
 * spring does not work!
 */
private boolean processDirectory(final File root, final File file, final IClasspathResourceVisitor visitor) {
    final String fullPath = file.getAbsolutePath();
    final String resourcePath = createResourcePath(root, file) + "/";
    return visitor.visit(fullPath, resourcePath, new FastByteArrayInputStream(Bytes.EMPTY_ARRAY));
}
Also used : FastByteArrayInputStream(it.unimi.dsi.fastutil.io.FastByteArrayInputStream)

Aggregations

FastByteArrayInputStream (it.unimi.dsi.fastutil.io.FastByteArrayInputStream)6 IOException (java.io.IOException)5 BlockVector3 (cn.nukkit.math.BlockVector3)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)2 EncoderException (io.netty.handler.codec.EncoderException)2 UncheckedIOException (java.io.UncheckedIOException)2 IBeanTableWriter (de.invesdwin.context.integration.csv.writer.IBeanTableWriter)1 RetryLaterRuntimeException (de.invesdwin.context.integration.retry.RetryLaterRuntimeException)1 PooledFastByteArrayOutputStream (de.invesdwin.util.streams.pool.PooledFastByteArrayOutputStream)1