Java Code Examples for org.bytedeco.javacpp.BytePointer#get()
The following examples show how to use
org.bytedeco.javacpp.BytePointer#get() .
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: ByteIndexer.java From tapir with MIT License | 6 votes |
/** * Creates a byte indexer to access efficiently the data of a pointer. * * @param pointer data to access via a buffer or to copy to an array * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new byte array backed by a buffer or an array */ public static ByteIndexer create(final BytePointer pointer, int[] sizes, int[] strides, boolean direct) { if (direct) { return new ByteBufferIndexer(pointer.asBuffer(), sizes, strides); } else { final int position = pointer.position(); byte[] array = new byte[pointer.limit() - position]; pointer.get(array); return new ByteArrayIndexer(array, sizes, strides) { @Override public void release() { pointer.position(position).put(array); super.release(); } }; } }
Example 2
Source File: FFmpegFrameRecorderPlus.java From easyCV with Apache License 2.0 | 5 votes |
@Override public int call(Pointer opaque, BytePointer buf, int buf_size) { try { byte[] b = new byte[buf_size]; OutputStream os = outputStreams.get(opaque); buf.get(b, 0, buf_size); os.write(b, 0, buf_size); return buf_size; } catch (Throwable t) { System.err.println("Error on OutputStream.write(): " + t); return -1; } }
Example 3
Source File: Hdf5Archive.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Read JSON-formatted string attribute. * * @param attribute HDF5 attribute to read as JSON formatted string. * @return JSON formatted string from HDF5 attribute * @throws UnsupportedKerasConfigurationException Unsupported Keras config */ private String readAttributeAsJson(Attribute attribute) throws UnsupportedKerasConfigurationException { synchronized (Hdf5Archive.LOCK_OBJECT) { VarLenType vl = attribute.getVarLenType(); int currBufferLength = 2048; String s; /* TODO: find a less hacky way to do this. * Reading variable length strings (from attributes) is a giant * pain. There does not appear to be any way to determine the * length of the string in advance, so we use a hack: choose a * buffer size and read the config. If Jackson fails to parse * it, then we must not have read the entire config. Increase * buffer and repeat. */ while (true) { byte[] attrBuffer = new byte[currBufferLength]; BytePointer attrPointer = new BytePointer(currBufferLength); attribute.read(vl, attrPointer); attrPointer.get(attrBuffer); s = new String(attrBuffer); ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY); try { mapper.readTree(s); break; } catch (IOException e) { //OK - we don't know how long the buffer needs to be, so we'll try again with larger buffer } if(currBufferLength == MAX_BUFFER_SIZE_BYTES){ throw new UnsupportedKerasConfigurationException("Could not read abnormally long HDF5 attribute: size exceeds " + currBufferLength + " bytes"); } else { currBufferLength = (int)Math.min(MAX_BUFFER_SIZE_BYTES, currBufferLength * 4L); } } vl.deallocate(); return s; } }
Example 4
Source File: Hdf5Archive.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Read attribute as string. * * @param attribute HDF5 attribute to read as string. * @return HDF5 attribute as string * @throws UnsupportedKerasConfigurationException Unsupported Keras config */ private String readAttributeAsString(Attribute attribute) throws UnsupportedKerasConfigurationException { synchronized (Hdf5Archive.LOCK_OBJECT) { VarLenType vl = attribute.getVarLenType(); int bufferSizeMult = 1; String s = null; /* TODO: find a less hacky way to do this. * Reading variable length strings (from attributes) is a giant * pain. There does not appear to be any way to determine the * length of the string in advance, so we use a hack: choose a * buffer size and read the config, increase buffer and repeat * until the buffer ends with \u0000 */ while (true) { byte[] attrBuffer = new byte[bufferSizeMult * 2000]; BytePointer attrPointer = new BytePointer(attrBuffer); attribute.read(vl, attrPointer); attrPointer.get(attrBuffer); s = new String(attrBuffer); if (s.endsWith("\u0000")) { s = s.replace("\u0000", ""); break; } bufferSizeMult++; if (bufferSizeMult > 1000) { throw new UnsupportedKerasConfigurationException("Could not read abnormally long HDF5 attribute"); } } vl.deallocate(); return s; } }
Example 5
Source File: Hdf5Archive.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Read attribute of fixed buffer size as string. * * @param attribute HDF5 attribute to read as string. * @return Fixed-length string read from HDF5 attribute * @throws UnsupportedKerasConfigurationException Unsupported Keras config */ private String readAttributeAsFixedLengthString(Attribute attribute, int bufferSize) throws UnsupportedKerasConfigurationException { synchronized (Hdf5Archive.LOCK_OBJECT) { VarLenType vl = attribute.getVarLenType(); byte[] attrBuffer = new byte[bufferSize]; BytePointer attrPointer = new BytePointer(attrBuffer); attribute.read(vl, attrPointer); attrPointer.get(attrBuffer); vl.deallocate(); return new String(attrBuffer); } }
Example 6
Source File: Convert.java From vlpr4j with Apache License 2.0 | 4 votes |
public static float toFloat(BytePointer pointer) { byte[] buffer = new byte[4]; pointer.get(buffer); return toFloat(buffer); }
Example 7
Source File: Convert.java From vlpr4j with Apache License 2.0 | 4 votes |
public static double toDouble(BytePointer pointer) { byte[] buffer = new byte[8]; pointer.get(buffer); return toDouble(buffer); }
Example 8
Source File: Convert.java From vlpr4j with Apache License 2.0 | 4 votes |
public static int toInt(BytePointer pointer) { byte[] buffer = new byte[4]; pointer.get(buffer); return toInt(buffer); }
Example 9
Source File: Convert.java From vlpr4j with Apache License 2.0 | 4 votes |
public static long toLong(BytePointer pointer) { byte[] buffer = new byte[8]; pointer.get(buffer); return toLong(buffer); }
Example 10
Source File: Convert.java From EasyPR-Java with Apache License 2.0 | 4 votes |
public static float toFloat(BytePointer pointer) { byte[] buffer = new byte[4]; pointer.get(buffer); return toFloat(buffer); }
Example 11
Source File: Convert.java From EasyPR-Java with Apache License 2.0 | 4 votes |
public static double toDouble(BytePointer pointer) { byte[] buffer = new byte[8]; pointer.get(buffer); return toDouble(buffer); }
Example 12
Source File: Convert.java From EasyPR-Java with Apache License 2.0 | 4 votes |
public static int toInt(BytePointer pointer) { byte[] buffer = new byte[4]; pointer.get(buffer); return toInt(buffer); }
Example 13
Source File: Convert.java From EasyPR-Java with Apache License 2.0 | 4 votes |
public static long toLong(BytePointer pointer) { byte[] buffer = new byte[8]; pointer.get(buffer); return toLong(buffer); }