/** * Converts the specified {@link String} to a NUL-terminated C string of * ASCII characters. Non ASCII characters will be replaced with '?' in the * result. The memory will be allocated on the GCed heaped. This method is * more efficient than using {@link #toStringZ(Charset)} with ASCII as * {@link Charset}. * * @param s the {@link String} to convert. * @return a {@link BytePtr} which points to the first character in the result. */ public static BytePtr toBytePtrAsciiZ(String s) { return toBytePtrAsciiZ(s, false); }
/** * @since Available in iOS 2.0 and later. */ public static CGBitmapContext create(byte[] data, long width, long height, long bitsPerComponent, long bytesPerRow, CGColorSpace space, CGBitmapInfo bitmapInfo) { BytePtr ptr = new BytePtr(); ptr.set(data); return create(ptr.as(IntPtr.class), width, height, bitsPerComponent, bytesPerRow, space, bitmapInfo); } /**
/** * Copies {@code count} bytes from the memory pointed to by this * {@link BytePtr} to {@code dst} starting at offset {@code offset}. * * @param dst the destination. * @param offset the offset within the destination array to start copying to. * @param count the number of elements to copy. */ public void get(byte[] dst, int offset, int count) { asByteBuffer(count).get(dst, offset, count); }
public static String getMachineString () { BytePtr name = BytePtr.toBytePtrAsciiZ("hw.machine"); MachineSizedUIntPtr size = new MachineSizedUIntPtr(); sysctlbyname(name, null, size, null, 0); BytePtr machine = Struct.allocate(BytePtr.class, (int) size.get()); sysctlbyname(name, machine.as(VoidPtr.class), size, null, 0); return machine.toStringAsciiZ(); }
/** * Converts the specified {@link String} to a NUL-terminated C string using * the specified {@link Charset}. Illegal characters will be replaced with * '?' in the result. The memory will be allocated on the GCed heaped. * * @param s the {@link String} to convert. * @param charset the {@link Charset} to use. Must be an 8-bit or variable * length character encoding with 8-bits as smallest value and that * can be NUL-terminated (e.g. UTF-8). * @return a {@link BytePtr} which points to the first character in the result. */ public static BytePtr toBytePtrZ(String s, Charset charset) { return toBytePtrZ(s, charset, false); }
/** * Returns a {@link ByteBuffer} which reads and writes to the same memory * location pointed to by this {@link BytePtr}. * * @param n the maximum number of bytes the {@link ByteBuffer} can * read/write. This will be the {@link ByteBuffer}'s * <code>capacity</code>. * @return the {@link ByteBuffer}. */ public ByteBuffer asByteBuffer(int n) { return VM.newDirectByteBuffer(getHandle(), n); }
/** * Returns a {@link String} created from the NUL-terminated C string pointed * to by this {@link BytePtr} using the default {@link Charset}. Illegal * characters will be replaced with '?' in the result. This assumes that * the default {@link Charset} is an 8-bit encoding or a variable length * encoding with 8-bits as smallest bit length such as UTF-8. * * @return a {@link String} converted from the C string bytes. */ public String toStringZ() { return toStringZ(Charset.defaultCharset()); }
/** * Returns a {@link String} created from the NUL-terminated C string pointed * to by this {@link BytePtr} using the specified {@link Charset}. Illegal * characters will be replaced with '?' in the result. * * @param charset the {@link Charset} to use. Must be an 8-bit or variable * length character encoding with 8-bits as smallest value and that * can be NUL-terminated (e.g. UTF-8). * @return a {@link String} converted from the C string bytes. */ public String toStringZ(Charset charset) { int length = 0; long address = getHandle(); while (VM.getByte(address++) != 0) { length++; } return charset.decode(asByteBuffer(length)).toString(); }
/** * Copies {@code n} bytes from the memory pointed to by this {@link BytePtr} * to a new {@code byte[]} instance. * * @param n the number of bytes to copy. * @return the {@code byte[]}. */ public byte[] toByteArray(int n) { byte[] result = new byte[n]; get(result); return result; }
/** * @throws OSStatusException * @since Available in iOS 4.0 and later. */ public CMTextJustification getVerticalJustification() throws OSStatusException { BytePtr ptr = new BytePtr(); OSStatus status = getJustification0(null, ptr); OSStatusException.throwIfNecessary(status); return CMTextJustification.valueOf(ptr.get()); } /**
/** * Copies {@code src.length} bytes from {@code src} to the memory pointed to by * this {@link BytePtr}. * * @param src the source. */ public void set(byte[] src) { set(src, 0, src.length); }
/** * @throws OSStatusException * @since Available in iOS 5.0 and later. */ public String getPeerDomainName() throws OSStatusException { BytePtr peerNamePtr = new BytePtr(); MachineSizedUIntPtr peerNameLenPtr = new MachineSizedUIntPtr(); OSStatus status = getPeerDomainName0(peerNamePtr, peerNameLenPtr); OSStatusException.throwIfNecessary(status); return peerNamePtr.toStringZ(); } /**
public static String getMachineString () { BytePtr name = BytePtr.toBytePtrAsciiZ("hw.machine"); MachineSizedUIntPtr size = new MachineSizedUIntPtr(); sysctlbyname(name, null, size, null, 0); BytePtr machine = Struct.allocate(BytePtr.class, (int) size.get()); sysctlbyname(name, machine.as(VoidPtr.class), size, null, 0); return machine.toStringAsciiZ(); }
/** * Converts the specified {@link String} to a NUL-terminated C string using * the default {@link Charset}. Illegal characters will be replaced with * '?' in the result. The memory will be allocated on the GCed heaped. * This assumes that the default {@link Charset} is an 8-bit encoding or a * variable length encoding with 8-bits as smallest bit length such as * UTF-8. * * @param s the {@link String} to convert. * @return a {@link BytePtr} which points to the first character in the result. */ public static BytePtr toBytePtrZ(String s) { return toBytePtrZ(s, Charset.defaultCharset(), false); }
public long read(BytePtr buffer, long len) { return read(buffer.getHandle(), len); } public long read(ByteBuffer bytes) {
/** * @since Available in iOS 2.0 and later. */ public static String getStatusDescription(SCStatusCode status) { BytePtr ptr = getStatusDescription0(status); return ptr.toStringZ(); } /*<methods>*/