/** * Construct an SObject with random generated key, byte array and number of bytes * @param buf the source byte array * @param len the number of bytes in the array should be stored in the returing object * @return an SObject as described above */ public static SObject of(byte[] buf, int len) { return of(randomKey(), buf, len); }
/** * Construct an sobject with specified content in String and a randomly * generated key * * @see #of(String, String) */ public static SObject of(String content) { return new StringSObject(randomKey(), content); }
/** * Construct an sobject with specified content in String and a randomly * generated key * * @see #of(String, String) */ public static SObject of(String content) { return new StringSObject(randomKey(), content); }
/** * Construct an SObject with random generated key, byte array and number of bytes * @param buf the source byte array * @param len the number of bytes in the array should be stored in the returing object * @return an SObject as described above */ public static SObject of(byte[] buf, int len) { return of(randomKey(), buf, len); }
/** * Construct an sobject with content in byte array and * a random generated key * * @see #of(String, byte[]) */ public static SObject of(byte[] buf) { return of(randomKey(), $.requireNotNull(buf)); }
/** * Construct an sobject with specified input stream and a randomly * generated key. * <p> * <p>Node the sobject constrcuted from input stream has limits * please see the comment to {@link #of(String, InputStream)} * </p> * * @see #of(String, InputStream) */ public static SObject of(InputStream is) { return of(randomKey(), $.requireNotNull(is)); }
/** * Construct an sobject with content in byte array and * a random generated key * * @see #of(String, byte[]) */ public static SObject of(byte[] buf) { return of(randomKey(), $.requireNotNull(buf)); }
/** * Construct an sobject with specified input stream and a randomly * generated key. * <p> * <p>Node the sobject constrcuted from input stream has limits * please see the comment to {@link #of(String, InputStream)} * </p> * * @see #of(String, InputStream) */ public static SObject of(InputStream is) { return of(randomKey(), $.requireNotNull(is)); }
/** * Load an sobject from classpath by given url path * * This method will call {@link Class#getResource(String)} method to open * an inputstream to the resource and then construct an SObject with the * inputstream * * @param url the resource url path * @return the sobject instance if loaded successfully or `null` if cannot load resource from the url */ public static SObject loadResource(String url) { InputStream is = SObject.class.getResourceAsStream(url); if (null == is) { return null; } String filename = S.afterLast(url, "/"); if (S.blank(filename)) { filename = url; } return of(randomKey(), is, ATTR_FILE_NAME, filename); }
/** * Load an sobject from classpath by given url path * * This method will call {@link Class#getResource(String)} method to open * an inputstream to the resource and then construct an SObject with the * inputstream * * @param url the resource url path * @return the sobject instance if loaded successfully or `null` if cannot load resource from the url */ public static SObject loadResource(String url) { InputStream is = SObject.class.getResourceAsStream(url); if (null == is) { return null; } String filename = S.afterLast(url, "/"); if (S.blank(filename)) { filename = url; } return of(randomKey(), is, ATTR_FILE_NAME, filename); }