libcore.io.Memory Java Examples
The following examples show how to use
libcore.io.Memory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteBufferAsCharBuffer.java From j2objc with Apache License 2.0 | 6 votes |
public CharBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (!(bb instanceof DirectByteBuffer)) { System.arraycopy(bb.array(), ix(pos), bb.array(), ix(0), rem << 1); } else { Memory.memmove(this, ix(0), this, ix(pos), rem << 1); } position(rem); limit(capacity()); discardMark(); return this; }
Example #2
Source File: ByteBufferAsLongBuffer.java From j2objc with Apache License 2.0 | 6 votes |
public LongBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (!(bb instanceof DirectByteBuffer)) { System.arraycopy(bb.array(), ix(pos), bb.array(), ix(0), rem << 3); } else { Memory.memmove(this, ix(0), this, ix(pos), rem << 3); } position(rem); limit(capacity()); discardMark(); return this; }
Example #3
Source File: ZipInputStream.java From jtransc with Apache License 2.0 | 6 votes |
private void readAndVerifyDataDescriptor(int inB, int out) throws IOException { if (hasDD) { Streams.readFully(in, hdrBuf, 0, EXTHDR); int sig = Memory.peekInt(hdrBuf, 0, true); if (sig != (int) EXTSIG) { throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig)); } currentEntry.crc = ((long) Memory.peekInt(hdrBuf, EXTCRC, true)) & 0xffffffffL; currentEntry.compressedSize = ((long) Memory.peekInt(hdrBuf, EXTSIZ, true)) & 0xffffffffL; currentEntry.size = ((long) Memory.peekInt(hdrBuf, EXTLEN, true)) & 0xffffffffL; } if (currentEntry.crc != crc.getValue()) { throw new ZipException("CRC mismatch"); } if (currentEntry.compressedSize != inB || currentEntry.size != out) { throw new ZipException("Size mismatch"); } }
Example #4
Source File: ByteBufferAsIntBuffer.java From j2objc with Apache License 2.0 | 6 votes |
public IntBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (!(bb instanceof DirectByteBuffer)) { System.arraycopy(bb.array(), ix(pos), bb.array(), ix(0), rem << 2); } else { Memory.memmove(this, ix(0), this, ix(pos), rem << 2); } position(rem); limit(capacity()); discardMark(); return this; }
Example #5
Source File: UUID.java From jtransc with Apache License 2.0 | 6 votes |
private static UUID makeUuid(byte[] hash, int version) { long msb = Memory.peekLong(hash, 0, false); long lsb = Memory.peekLong(hash, 8, false); // Set the version field. msb &= ~(0xfL << 12); msb |= ((long) version) << 12; // Set the variant field to 2. Note that the variant field is variable-width, // so supporting other variants is not just a matter of changing the constant 2 below! lsb &= ~(0x3L << 62); lsb |= 2L << 62; return new UUID(msb, lsb); }
Example #6
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 6 votes |
@Override public ByteBuffer get(byte[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } checkBounds(dstOffset, length, dst.length); int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (length > rem) throw new BufferUnderflowException(); Memory.peekByteArray(ix(pos), dst, dstOffset, length); position = pos + length; return this; }
Example #7
Source File: ByteBufferAsFloatBuffer.java From j2objc with Apache License 2.0 | 6 votes |
public FloatBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (!(bb instanceof DirectByteBuffer)) { System.arraycopy(bb.array(), ix(pos), bb.array(), ix(0), rem << 2); } else { Memory.memmove(this, ix(0), this, ix(pos), rem << 2); } position(rem); limit(capacity()); discardMark(); return this; }
Example #8
Source File: ByteBufferAsShortBuffer.java From j2objc with Apache License 2.0 | 6 votes |
public ShortBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (!(bb instanceof DirectByteBuffer)) { System.arraycopy(bb.array(), ix(pos), bb.array(), ix(0), rem << 1); } else { Memory.memmove(this, ix(0), this, ix(pos), rem << 1); } position(rem); limit(capacity()); discardMark(); return this; }
Example #9
Source File: ObjectOutputStream.java From jtransc with Apache License 2.0 | 6 votes |
/** * Write String {@code object} into the receiver. It is assumed the * String has not been dumped yet. Returns the handle for this object (String) which is dumped here. * Strings are saved encoded with {@link DataInput modified UTF-8}. * * @param object * the string to dump. * @return the handle assigned to the String being dumped * * @throws IOException * If an IO exception happened when writing the String. */ private int writeNewString(String object, boolean unshared) throws IOException { long count = ModifiedUtf8.countBytes(object, false); byte[] buffer; int offset = 0; if (count <= 0xffff) { buffer = new byte[1 + SizeOf.SHORT + (int) count]; buffer[offset++] = TC_STRING; Memory.pokeShort(buffer, offset, (short) count, false); offset += SizeOf.SHORT; } else { buffer = new byte[1 + SizeOf.LONG + (int) count]; buffer[offset++] = TC_LONGSTRING; Memory.pokeLong(buffer, offset, count, false); offset += SizeOf.LONG; } ModifiedUtf8.encode(buffer, offset, object); output.write(buffer, 0, buffer.length); int handle = nextHandle(); if (!unshared) { objectsWritten.put(object, handle); } return handle; }
Example #10
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override char getCharUnchecked(int i) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } return (char) Memory.peekShort(ix(i), !nativeByteOrder); }
Example #11
Source File: ByteBufferAsShortBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override @HaxeMethodBody("this.tarray.set(p0, p1); return this;") @JTranscMethodBody(target = "js", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "dart", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cpp", value = "this->tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { ((short *)ptr)[p0] = p1; } } return this;") public ShortBuffer put(int index, short c) { Memory.pokeAlignedShortLE(bytes, index, c); return this; }
Example #12
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override public final char getChar() { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } int newPosition = position + Character.BYTES; if (newPosition > limit()) { throw new BufferUnderflowException(); } char x = (char) Memory.peekShort(ix(position), !nativeByteOrder); position = newPosition; return x; }
Example #13
Source File: ByteBufferAsCharBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override @HaxeMethodBody("this.tarray.set(p0, p1); return this;") @JTranscMethodBody(target = "js", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "dart", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cpp", value = "this->tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { ((ushort *)ptr)[p0] = p1; } } return this;") public CharBuffer put(int index, char c) { Memory.pokeAlignedCharLE(bytes, index, c); return this; }
Example #14
Source File: ByteBufferAsCharBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override @HaxeMethodBody("return N.i2s(this.tarray.get(p0));") @JTranscMethodBody(target = "js", value = "return this.tarray[p0];") @JTranscMethodBody(target = "dart", value = "return this.tarray[p0];") @JTranscMethodBody(target = "cpp", value = "return this->tarray[p0];") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { return ((ushort *)ptr)[p0]; } }") public char get(int index) { return Memory.peekAlignedCharLE(bytes, index); }
Example #15
Source File: ByteBufferAsLongBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override @HaxeMethodBody("this.tarray.set(p0 * 2 + 0, N.llow(p1)); this.tarray.set(p0 * 2 + 1, N.lhigh(p1)); return this;") @JTranscMethodBody(target = "js", value = "this.tarray[p0 * 2 + 0] = p1.low; this.tarray[p0 * 2 + 1] = p1.high; return this;") @JTranscMethodBody(target = "dart", value = "this.tarray[p0] = p1.toInt(); return this;") @JTranscMethodBody(target = "cpp", value = "this->tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { ((long *)ptr)[p0] = p1; } } return this;") public LongBuffer put(int index, long c) { Memory.pokeAlignedLongLE(bytes, index, c); return this; }
Example #16
Source File: ByteBufferAsLongBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override @HaxeMethodBody("var low = this.tarray.get(p0 * 2 + 0); var high = this.tarray.get(p0 * 2 + 1); return N.lnew(high, low);") @JTranscMethodBody(target = "js", value = "var low = this.tarray[p0 * 2 + 0]; var high = this.tarray[p0 * 2 + 1]; return N.lnew(high, low);") @JTranscMethodBody(target = "dart", value = "return N.lnew(this.tarray[p0]);") @JTranscMethodBody(target = "cpp", value = "return this->tarray[p0];") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { return ((long *)ptr)[p0]; } }") public long get(int index) { return Memory.peekAlignedLongLE(bytes, index); }
Example #17
Source File: ByteBufferAsDoubleBuffer.java From jtransc with Apache License 2.0 | 5 votes |
@Override //@HaxeMethodBody("this.tarray.set(p0, p1); return this;") @JTranscMethodBody(target = "js", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "dart", value = "this.tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cpp", value = "this->tarray[p0] = p1; return this;") @JTranscMethodBody(target = "cs", value = "unsafe { fixed (byte* ptr = this.tarray) { ((double *)ptr)[p0] = p1; } } return this;") public DoubleBuffer put(int index, double c) { Memory.pokeAlignedDoubleLE(bytes, index, c); return this; }
Example #18
Source File: FileBridge.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void writeCommandAndBlock(int cmd, String cmdString) throws IOException { Memory.pokeInt(mTemp, 0, cmd, ByteOrder.BIG_ENDIAN); IoBridge.write(mClient, mTemp, 0, MSG_LENGTH); // Wait for server to ack if (IoBridge.read(mClient, mTemp, 0, MSG_LENGTH) == MSG_LENGTH) { if (Memory.peekInt(mTemp, 0, ByteOrder.BIG_ENDIAN) == cmd) { return; } } throw new IOException("Failed to execute " + cmdString + " across bridge"); }
Example #19
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override void getUnchecked(int pos, char[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.peekCharArray(ix(pos), dst, dstOffset, length, !nativeByteOrder); }
Example #20
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override void putUnchecked(int pos, char[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeCharArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }
Example #21
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override void getUnchecked(int pos, short[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.peekShortArray(ix(pos), dst, dstOffset, length, !nativeByteOrder); }
Example #22
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override void putUnchecked(int pos, short[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeShortArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }
Example #23
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void getUnchecked(int pos, int[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.peekIntArray(ix(pos), dst, dstOffset, length, !nativeByteOrder); }
Example #24
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void putUnchecked(int pos, int[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeIntArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }
Example #25
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
private long getLong(long a) { return Memory.peekLong(a, !nativeByteOrder); }
Example #26
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void putUnchecked(int pos, long[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeLongArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }
Example #27
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void getUnchecked(int pos, float[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.peekFloatArray(ix(pos), dst, dstOffset, length, !nativeByteOrder); }
Example #28
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void putUnchecked(int pos, float[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeFloatArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }
Example #29
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void getUnchecked(int pos, double[] dst, int dstOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.peekDoubleArray(ix(pos), dst, dstOffset, length, !nativeByteOrder); }
Example #30
Source File: DirectByteBuffer.java From j2objc with Apache License 2.0 | 5 votes |
@Override final void putUnchecked(int pos, double[] src, int srcOffset, int length) { if (!memoryRef.isAccessible) { throw new IllegalStateException("buffer is inaccessible"); } Memory.pokeDoubleArray(ix(pos), src, srcOffset, length, !nativeByteOrder); }