3111 * installed, the {@link SecurityManager#checkRead(String) checkRead} 3112 * method is invoked to check read access to the file. 3113 */ 3114 public static long copy(Path source, OutputStream out) throws IOException { 3115 // ensure not null before opening file 3116 Objects.requireNonNull(out); 3117 3118 try (InputStream in = newInputStream(source)) { 3119 return in.transferTo(out); 3120 } 3121 } 3122 3123 /** 3124 * The maximum size of array to allocate. 3125 * Some VMs reserve some header words in an array. 3126 * Attempts to allocate larger arrays may result in 3127 * OutOfMemoryError: Requested array size exceeds VM limit 3128 */ 3129 private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; 3130 3131 private static final jdk.internal.misc.JavaLangAccess JLA = 3132 jdk.internal.misc.SharedSecrets.getJavaLangAccess(); 3133 3134 /** 3135 * Reads all the bytes from an input stream. Uses {@code initialSize} as a hint 3136 * about how many bytes the stream will have. 3137 * 3138 * @param source 3139 * the input stream to read from 3140 * @param initialSize 3141 * the initial size of the byte array to allocate 3142 * 3143 * @return a byte array containing the bytes read from the file 3144 * 3145 * @throws IOException 3146 * if an I/O error occurs reading from the stream 3147 * @throws OutOfMemoryError 3148 * if an array of the required size cannot be allocated 3149 */ 3150 private static byte[] read(InputStream source, int initialSize) throws IOException { 3151 int capacity = initialSize; 3152 byte[] buf = new byte[capacity]; | 3111 * installed, the {@link SecurityManager#checkRead(String) checkRead} 3112 * method is invoked to check read access to the file. 3113 */ 3114 public static long copy(Path source, OutputStream out) throws IOException { 3115 // ensure not null before opening file 3116 Objects.requireNonNull(out); 3117 3118 try (InputStream in = newInputStream(source)) { 3119 return in.transferTo(out); 3120 } 3121 } 3122 3123 /** 3124 * The maximum size of array to allocate. 3125 * Some VMs reserve some header words in an array. 3126 * Attempts to allocate larger arrays may result in 3127 * OutOfMemoryError: Requested array size exceeds VM limit 3128 */ 3129 private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; 3130 3131 private static final jdk.internal.access.JavaLangAccess JLA = 3132 jdk.internal.access.SharedSecrets.getJavaLangAccess(); 3133 3134 /** 3135 * Reads all the bytes from an input stream. Uses {@code initialSize} as a hint 3136 * about how many bytes the stream will have. 3137 * 3138 * @param source 3139 * the input stream to read from 3140 * @param initialSize 3141 * the initial size of the byte array to allocate 3142 * 3143 * @return a byte array containing the bytes read from the file 3144 * 3145 * @throws IOException 3146 * if an I/O error occurs reading from the stream 3147 * @throws OutOfMemoryError 3148 * if an array of the required size cannot be allocated 3149 */ 3150 private static byte[] read(InputStream source, int initialSize) throws IOException { 3151 int capacity = initialSize; 3152 byte[] buf = new byte[capacity]; |