581 /**
582 * Returns a request body publisher whose body is the given byte array.
583 *
584 * @param buf the byte array containing the body
585 * @return a BodyPublisher
586 */
587 public static BodyPublisher ofByteArray(byte[] buf) {
588 return new RequestPublishers.ByteArrayPublisher(buf);
589 }
590
591 /**
592 * Returns a request body publisher whose body is the content of the
593 * given byte array of {@code length} bytes starting from the specified
594 * {@code offset}.
595 *
596 * @param buf the byte array containing the body
597 * @param offset the offset of the first byte
598 * @param length the number of bytes to use
599 * @return a BodyPublisher
600 * @throws IndexOutOfBoundsException if the sub-range is defined to be
601 * out-of-bounds
602 */
603 public static BodyPublisher ofByteArray(byte[] buf, int offset, int length) {
604 Objects.checkFromIndexSize(offset, length, buf.length);
605 return new RequestPublishers.ByteArrayPublisher(buf, offset, length);
606 }
607
608 /**
609 * A request body publisher that takes data from the contents of a File.
610 *
611 * <p> Security manager permission checks are performed in this factory
612 * method, when the {@code BodyPublisher} is created. Care must be taken
613 * that the {@code BodyPublisher} is not shared with untrusted code.
614 *
615 * @param path the path to the file containing the body
616 * @return a BodyPublisher
617 * @throws java.io.FileNotFoundException if the path is not found
618 * @throws SecurityException if a security manager has been installed
619 * and it denies {@link SecurityManager#checkRead(String)
620 * read access} to the given file
621 */
|
581 /**
582 * Returns a request body publisher whose body is the given byte array.
583 *
584 * @param buf the byte array containing the body
585 * @return a BodyPublisher
586 */
587 public static BodyPublisher ofByteArray(byte[] buf) {
588 return new RequestPublishers.ByteArrayPublisher(buf);
589 }
590
591 /**
592 * Returns a request body publisher whose body is the content of the
593 * given byte array of {@code length} bytes starting from the specified
594 * {@code offset}.
595 *
596 * @param buf the byte array containing the body
597 * @param offset the offset of the first byte
598 * @param length the number of bytes to use
599 * @return a BodyPublisher
600 * @throws IndexOutOfBoundsException if the sub-range is defined to be
601 * out of bounds
602 */
603 public static BodyPublisher ofByteArray(byte[] buf, int offset, int length) {
604 Objects.checkFromIndexSize(offset, length, buf.length);
605 return new RequestPublishers.ByteArrayPublisher(buf, offset, length);
606 }
607
608 /**
609 * A request body publisher that takes data from the contents of a File.
610 *
611 * <p> Security manager permission checks are performed in this factory
612 * method, when the {@code BodyPublisher} is created. Care must be taken
613 * that the {@code BodyPublisher} is not shared with untrusted code.
614 *
615 * @param path the path to the file containing the body
616 * @return a BodyPublisher
617 * @throws java.io.FileNotFoundException if the path is not found
618 * @throws SecurityException if a security manager has been installed
619 * and it denies {@link SecurityManager#checkRead(String)
620 * read access} to the given file
621 */
|