OLD | NEW |
| (Empty) |
1 /* | |
2 * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 * contributor license agreements. See the NOTICE file distributed with | |
4 * this work for additional information regarding copyright ownership. | |
5 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 * (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package org.apache.tomcat.jni; | |
19 /* Import needed classes */ | |
20 import java.nio.ByteBuffer; | |
21 | |
22 /** File | |
23 * | |
24 * @author Mladen Turk | |
25 */ | |
26 public class File { | |
27 | |
28 /** Open the file for reading */ | |
29 public static final int APR_FOPEN_READ = 0x00001; | |
30 /** Open the file for writing */ | |
31 public static final int APR_FOPEN_WRITE = 0x00002; | |
32 /** Create the file if not there */ | |
33 public static final int APR_FOPEN_CREATE = 0x00004; | |
34 /** Append to the end of the file */ | |
35 public static final int APR_FOPEN_APPEND = 0x00008; | |
36 /** Open the file and truncate to 0 length */ | |
37 public static final int APR_FOPEN_TRUNCATE = 0x00010; | |
38 /** Open the file in binary mode */ | |
39 public static final int APR_FOPEN_BINARY = 0x00020; | |
40 /** Open should fail if APR_CREATE and file exists. */ | |
41 public static final int APR_FOPEN_EXCL = 0x00040; | |
42 /** Open the file for buffered I/O */ | |
43 public static final int APR_FOPEN_BUFFERED = 0x00080; | |
44 /** Delete the file after close */ | |
45 public static final int APR_FOPEN_DELONCLOSE = 0x00100; | |
46 /** Platform dependent tag to open the file for | |
47 * use across multiple threads | |
48 */ | |
49 public static final int APR_FOPEN_XTHREAD = 0x00200; | |
50 /** Platform dependent support for higher level locked read/write | |
51 * access to support writes across process/machines | |
52 */ | |
53 public static final int APR_FOPEN_SHARELOCK = 0x00400; | |
54 /** Do not register a cleanup when the file is opened */ | |
55 public static final int APR_FOPEN_NOCLEANUP = 0x00800; | |
56 /** Advisory flag that this file should support | |
57 * apr_socket_sendfile operation | |
58 */ | |
59 public static final int APR_FOPEN_SENDFILE_ENABLED = 0x01000; | |
60 /** Platform dependent flag to enable large file support; | |
61 * <br><b>Warning :</b> The APR_LARGEFILE flag only has effect on some platf
orms | |
62 * where sizeof(apr_off_t) == 4. Where implemented, it allows opening | |
63 * and writing to a file which exceeds the size which can be | |
64 * represented by apr_off_t (2 gigabytes). When a file's size does | |
65 * exceed 2Gb, apr_file_info_get() will fail with an error on the | |
66 * descriptor, likewise apr_stat()/apr_lstat() will fail on the | |
67 * filename. apr_dir_read() will fail with APR_INCOMPLETE on a | |
68 * directory entry for a large file depending on the particular | |
69 * APR_FINFO_* flags. Generally, it is not recommended to use this | |
70 * flag. | |
71 */ | |
72 public static final int APR_FOPEN_LARGEFILE = 0x04000; | |
73 | |
74 /** Set the file position */ | |
75 public static final int APR_SET = 0; | |
76 /** Current */ | |
77 public static final int APR_CUR = 1; | |
78 /** Go to end of file */ | |
79 public static final int APR_END = 2; | |
80 | |
81 /* flags for apr_file_attrs_set */ | |
82 | |
83 /** File is read-only */ | |
84 public static final int APR_FILE_ATTR_READONLY = 0x01; | |
85 /** File is executable */ | |
86 public static final int APR_FILE_ATTR_EXECUTABLE = 0x02; | |
87 /** File is hidden */ | |
88 public static final int APR_FILE_ATTR_HIDDEN = 0x04; | |
89 | |
90 | |
91 /* File lock types/flags */ | |
92 | |
93 /** Shared lock. More than one process or thread can hold a shared lock | |
94 * at any given time. Essentially, this is a "read lock", preventing | |
95 * writers from establishing an exclusive lock. | |
96 */ | |
97 public static final int APR_FLOCK_SHARED = 1; | |
98 | |
99 /** Exclusive lock. Only one process may hold an exclusive lock at any | |
100 * given time. This is analogous to a "write lock". | |
101 */ | |
102 public static final int APR_FLOCK_EXCLUSIVE = 2; | |
103 /** mask to extract lock type */ | |
104 public static final int APR_FLOCK_TYPEMASK = 0x000F; | |
105 /** do not block while acquiring the file lock */ | |
106 public static final int APR_FLOCK_NONBLOCK = 0x0010; | |
107 | |
108 /* apr_filetype_e values for the filetype member of the | |
109 * apr_file_info_t structure | |
110 * <br><b>Warning :</b>: Not all of the filetypes below can be determined. | |
111 * For example, a given platform might not correctly report | |
112 * a socket descriptor as APR_SOCK if that type isn't | |
113 * well-identified on that platform. In such cases where | |
114 * a filetype exists but cannot be described by the recognized | |
115 * flags below, the filetype will be APR_UNKFILE. If the | |
116 * filetype member is not determined, the type will be APR_NOFILE. | |
117 */ | |
118 | |
119 /** no file type determined */ | |
120 public static final int APR_NOFILE = 0; | |
121 /** a regular file */ | |
122 public static final int APR_REG = 1; | |
123 /** a directory */ | |
124 public static final int APR_DIR = 2; | |
125 /** a character device */ | |
126 public static final int APR_CHR = 3; | |
127 /** a block device */ | |
128 public static final int APR_BLK = 4; | |
129 /** a FIFO / pipe */ | |
130 public static final int APR_PIPE = 5; | |
131 /** a symbolic link */ | |
132 public static final int APR_LNK = 6; | |
133 /** a [unix domain] socket */ | |
134 public static final int APR_SOCK = 7; | |
135 /** a file of some other unknown type */ | |
136 public static final int APR_UNKFILE = 127; | |
137 | |
138 | |
139 /* | |
140 * apr_file_permissions File Permissions flags | |
141 */ | |
142 | |
143 public static final int APR_FPROT_USETID = 0x8000; /** Set user id */ | |
144 public static final int APR_FPROT_UREAD = 0x0400; /** Read by user */ | |
145 public static final int APR_FPROT_UWRITE = 0x0200; /** Write by user */ | |
146 public static final int APR_FPROT_UEXECUTE = 0x0100; /** Execute by user *
/ | |
147 | |
148 public static final int APR_FPROT_GSETID = 0x4000; /** Set group id */ | |
149 public static final int APR_FPROT_GREAD = 0x0040; /** Read by group */ | |
150 public static final int APR_FPROT_GWRITE = 0x0020; /** Write by group */ | |
151 public static final int APR_FPROT_GEXECUTE = 0x0010; /** Execute by group
*/ | |
152 | |
153 public static final int APR_FPROT_WSTICKY = 0x2000; /** Sticky bit */ | |
154 public static final int APR_FPROT_WREAD = 0x0004; /** Read by others */ | |
155 public static final int APR_FPROT_WWRITE = 0x0002; /** Write by others *
/ | |
156 public static final int APR_FPROT_WEXECUTE = 0x0001; /** Execute by others
*/ | |
157 public static final int APR_FPROT_OS_DEFAULT = 0x0FFF; /** use OS's default
permissions */ | |
158 | |
159 | |
160 public static final int APR_FINFO_LINK = 0x00000001; /** Stat the link not
the file itself if it is a link */ | |
161 public static final int APR_FINFO_MTIME = 0x00000010; /** Modification Time
*/ | |
162 public static final int APR_FINFO_CTIME = 0x00000020; /** Creation or inode
-changed time */ | |
163 public static final int APR_FINFO_ATIME = 0x00000040; /** Access Time */ | |
164 public static final int APR_FINFO_SIZE = 0x00000100; /** Size of the file
*/ | |
165 public static final int APR_FINFO_CSIZE = 0x00000200; /** Storage size cons
umed by the file */ | |
166 public static final int APR_FINFO_DEV = 0x00001000; /** Device */ | |
167 public static final int APR_FINFO_INODE = 0x00002000; /** Inode */ | |
168 public static final int APR_FINFO_NLINK = 0x00004000; /** Number of links *
/ | |
169 public static final int APR_FINFO_TYPE = 0x00008000; /** Type */ | |
170 public static final int APR_FINFO_USER = 0x00010000; /** User */ | |
171 public static final int APR_FINFO_GROUP = 0x00020000; /** Group */ | |
172 public static final int APR_FINFO_UPROT = 0x00100000; /** User protection b
its */ | |
173 public static final int APR_FINFO_GPROT = 0x00200000; /** Group protection
bits */ | |
174 public static final int APR_FINFO_WPROT = 0x00400000; /** World protection
bits */ | |
175 public static final int APR_FINFO_ICASE = 0x01000000; /** if dev is case in
sensitive */ | |
176 public static final int APR_FINFO_NAME = 0x02000000; /** ->name in prop
er case */ | |
177 | |
178 public static final int APR_FINFO_MIN = 0x00008170; /** type, mtime, ctim
e, atime, size */ | |
179 public static final int APR_FINFO_IDENT = 0x00003000; /** dev and inode */ | |
180 public static final int APR_FINFO_OWNER = 0x00030000; /** user and group */ | |
181 public static final int APR_FINFO_PROT = 0x00700000; /** all protections
*/ | |
182 public static final int APR_FINFO_NORM = 0x0073b170; /** an atomic unix a
pr_stat() */ | |
183 public static final int APR_FINFO_DIRENT = 0x02000000; /** an atomic unix a
pr_dir_read() */ | |
184 | |
185 | |
186 | |
187 /** | |
188 * Open the specified file. | |
189 * @param fname The full path to the file (using / on all systems) | |
190 * @param flag Or'ed value of: | |
191 * <PRE> | |
192 * APR_FOPEN_READ open for reading | |
193 * APR_FOPEN_WRITE open for writing | |
194 * APR_FOPEN_CREATE create the file if not there | |
195 * APR_FOPEN_APPEND file ptr is set to end prior to all writes | |
196 * APR_FOPEN_TRUNCATE set length to zero if file exists | |
197 * APR_FOPEN_BINARY not a text file (This flag is ignored on | |
198 * UNIX because it has no meaning) | |
199 * APR_FOPEN_BUFFERED buffer the data. Default is non-buffered | |
200 * APR_FOPEN_EXCL return error if APR_CREATE and file exists | |
201 * APR_FOPEN_DELONCLOSE delete the file after closing. | |
202 * APR_FOPEN_XTHREAD Platform dependent tag to open the file | |
203 * for use across multiple threads | |
204 * APR_FOPEN_SHARELOCK Platform dependent support for higher | |
205 * level locked read/write access to support | |
206 * writes across process/machines | |
207 * APR_FOPEN_NOCLEANUP Do not register a cleanup with the pool | |
208 * passed in on the <EM>pool</EM> argument (see
below). | |
209 * The apr_os_file_t handle in apr_file_t will n
ot | |
210 * be closed when the pool is destroyed. | |
211 * APR_FOPEN_SENDFILE_ENABLED Open with appropriate platform semantics | |
212 * for sendfile operations. Advisory only, | |
213 * apr_socket_sendfile does not check this flag. | |
214 * </PRE> | |
215 * @param perm Access permissions for file. | |
216 * @param pool The pool to use. | |
217 * If perm is APR_OS_DEFAULT and the file is being created, | |
218 * appropriate default permissions will be used. | |
219 * @return The opened file descriptor. | |
220 */ | |
221 public static native long open(String fname, int flag, int perm, long pool) | |
222 throws Error; | |
223 | |
224 /** | |
225 * Close the specified file. | |
226 * @param file The file descriptor to close. | |
227 */ | |
228 public static native int close(long file); | |
229 | |
230 /** | |
231 * Flush the file's buffer. | |
232 * @param thefile The file descriptor to flush | |
233 */ | |
234 public static native int flush(long thefile); | |
235 | |
236 /** | |
237 * Open a temporary file | |
238 * @param templ The template to use when creating a temp file. | |
239 * @param flags The flags to open the file with. If this is zero, | |
240 * the file is opened with | |
241 * APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOS
E | |
242 * @param pool The pool to allocate the file out of. | |
243 * @return The apr file to use as a temporary file. | |
244 * | |
245 * This function generates a unique temporary file name from template. | |
246 * The last six characters of template must be XXXXXX and these are replaced | |
247 * with a string that makes the filename unique. Since it will be modified
, | |
248 * template must not be a string constant, but should be declared as a chara
cter | |
249 * array. | |
250 * | |
251 */ | |
252 public static native long mktemp(String templ, int flags, long pool) | |
253 throws Error; | |
254 | |
255 /** | |
256 * Delete the specified file. | |
257 * @param path The full path to the file (using / on all systems) | |
258 * @param pool The pool to use. | |
259 * If the file is open, it won't be removed until all | |
260 * instances are closed. | |
261 */ | |
262 public static native int remove(String path, long pool); | |
263 | |
264 /** | |
265 * Rename the specified file. | |
266 * <br><b>Warning :</b> If a file exists at the new location, then it will b
e | |
267 * overwritten. Moving files or directories across devices may not be | |
268 * possible. | |
269 * @param fromPath The full path to the original file (using / on all system
s) | |
270 * @param toPath The full path to the new file (using / on all systems) | |
271 * @param pool The pool to use. | |
272 */ | |
273 public static native int rename(String fromPath, String toPath, long pool); | |
274 | |
275 /** | |
276 * Copy the specified file to another file. | |
277 * The new file does not need to exist, it will be created if required. | |
278 * <br><b>Warning :</b> If the new file already exists, its contents will be
overwritten. | |
279 * @param fromPath The full path to the original file (using / on all system
s) | |
280 * @param toPath The full path to the new file (using / on all systems) | |
281 * @param perms Access permissions for the new file if it is created. | |
282 * In place of the usual or'd combination of file permissions, the | |
283 * value APR_FILE_SOURCE_PERMS may be given, in which case the source | |
284 * file's permissions are copied. | |
285 * @param pool The pool to use. | |
286 */ | |
287 public static native int copy(String fromPath, String toPath, int perms, lon
g pool); | |
288 | |
289 /** | |
290 * Append the specified file to another file. | |
291 * The new file does not need to exist, it will be created if required. | |
292 * @param fromPath The full path to the source file (use / on all systems) | |
293 * @param toPath The full path to the destination file (use / on all systems
) | |
294 * @param perms Access permissions for the destination file if it is created
. | |
295 * In place of the usual or'd combination of file permissions, the | |
296 * value APR_FILE_SOURCE_PERMS may be given, in which case the source | |
297 * file's permissions are copied. | |
298 * @param pool The pool to use. | |
299 */ | |
300 public static native int append(String fromPath, String toPath, int perms, l
ong pool); | |
301 | |
302 /** | |
303 * Write the string into the specified file. | |
304 * @param str The string to write. Must be NUL terminated! | |
305 * @param thefile The file descriptor to write to | |
306 */ | |
307 public static native int puts(byte [] str, long thefile); | |
308 | |
309 /** | |
310 * Move the read/write file offset to a specified byte within a file. | |
311 * @param thefile The file descriptor | |
312 * @param where How to move the pointer, one of: | |
313 * <PRE> | |
314 * APR_SET -- set the offset to offset | |
315 * APR_CUR -- add the offset to the current position | |
316 * APR_END -- add the offset to the current file size | |
317 * </PRE> | |
318 * @param offset The offset to move the pointer to. | |
319 * @return Offset the pointer was actually moved to. | |
320 */ | |
321 public static native long seek(long thefile, int where, long offset) | |
322 throws Error; | |
323 | |
324 /** | |
325 * Write a character into the specified file. | |
326 * @param ch The character to write. | |
327 * @param thefile The file descriptor to write to | |
328 */ | |
329 public static native int putc(byte ch, long thefile); | |
330 | |
331 /** | |
332 * Put a character back onto a specified stream. | |
333 * @param ch The character to write. | |
334 * @param thefile The file descriptor to write to | |
335 */ | |
336 public static native int ungetc(byte ch, long thefile); | |
337 | |
338 /** | |
339 * Write data to the specified file. | |
340 * | |
341 * Write will write up to the specified number of | |
342 * bytes, but never more. If the OS cannot write that many bytes, it | |
343 * will write as many as it can. The third argument is modified to | |
344 * reflect the * number of bytes written. | |
345 * | |
346 * It is possible for both bytes to be written and an error to | |
347 * be returned. APR_EINTR is never returned. | |
348 * @param thefile The file descriptor to write to. | |
349 * @param buf The buffer which contains the data. | |
350 * @param offset Start offset in buf | |
351 * @param nbytes The number of bytes to write; (-1) for full array. | |
352 * @return The number of bytes written. | |
353 */ | |
354 public static native int write(long thefile, byte[] buf, int offset, int nby
tes); | |
355 | |
356 /** | |
357 * Write data to the specified file. | |
358 * | |
359 * Write will write up to the specified number of | |
360 * bytes, but never more. If the OS cannot write that many bytes, it | |
361 * will write as many as it can. The third argument is modified to | |
362 * reflect the * number of bytes written. | |
363 * | |
364 * It is possible for both bytes to be written and an error to | |
365 * be returned. APR_EINTR is never returned. | |
366 * @param thefile The file descriptor to write to. | |
367 * @param buf The direct Byte buffer which contains the data. | |
368 * @param offset Start offset in buf | |
369 * @param nbytes The number of bytes to write | |
370 * @return The number of bytes written. | |
371 */ | |
372 public static native int writeb(long thefile, ByteBuffer buf, int offset, in
t nbytes); | |
373 | |
374 /** | |
375 * Write data to the specified file, ensuring that all of the data is | |
376 * written before returning. | |
377 * | |
378 * Write will write up to the specified number of | |
379 * bytes, but never more. If the OS cannot write that many bytes, the | |
380 * process/thread will block until they can be written. Exceptional | |
381 * error such as "out of space" or "pipe closed" will terminate with | |
382 * an error. | |
383 * | |
384 * It is possible for both bytes to be written and an error to | |
385 * be returned. And if *bytes_written is less than nbytes, an | |
386 * accompanying error is _always_ returned. | |
387 * | |
388 * APR_EINTR is never returned. | |
389 * @param thefile The file descriptor to write to. | |
390 * @param buf The buffer which contains the data. | |
391 * @param offset Start offset in buf | |
392 * @param nbytes The number of bytes to write; (-1) for full array. | |
393 * @return The number of bytes written. | |
394 */ | |
395 public static native int writeFull(long thefile, byte[] buf, int offset, int
nbytes); | |
396 | |
397 /** | |
398 * Write data to the specified file, ensuring that all of the data is | |
399 * written before returning. | |
400 * | |
401 * Write will write up to the specified number of | |
402 * bytes, but never more. If the OS cannot write that many bytes, the | |
403 * process/thread will block until they can be written. Exceptional | |
404 * error such as "out of space" or "pipe closed" will terminate with | |
405 * an error. | |
406 * | |
407 * It is possible for both bytes to be written and an error to | |
408 * be returned. And if *bytes_written is less than nbytes, an | |
409 * accompanying error is _always_ returned. | |
410 * | |
411 * APR_EINTR is never returned. | |
412 * @param thefile The file descriptor to write to. | |
413 * @param buf The direct ByteBuffer which contains the data. | |
414 * @param offset Start offset in buf | |
415 * @param nbytes The number of bytes to write. | |
416 * @return The number of bytes written. | |
417 */ | |
418 public static native int writeFullb(long thefile, ByteBuffer buf, int offset
, int nbytes); | |
419 | |
420 /** | |
421 * Write data from array of byte arrays to the specified file. | |
422 * | |
423 * It is possible for both bytes to be written and an error to | |
424 * be returned. APR_EINTR is never returned. | |
425 * | |
426 * apr_file_writev is available even if the underlying | |
427 * operating system doesn't provide writev(). | |
428 * @param thefile The file descriptor to write to. | |
429 * @param vec The array from which to get the data to write to the file. | |
430 * @return The number of bytes written. | |
431 */ | |
432 public static native int writev(long thefile, byte[][] vec); | |
433 | |
434 /** | |
435 * Write data from array of byte arrays to the specified file, | |
436 * ensuring that all of the data is written before returning. | |
437 * | |
438 * writevFull is available even if the underlying | |
439 * operating system doesn't provide writev(). | |
440 * @param thefile The file descriptor to write to. | |
441 * @param vec The array from which to get the data to write to the file. | |
442 * @return The number of bytes written. | |
443 */ | |
444 public static native int writevFull(long thefile, byte[][] vec); | |
445 | |
446 /** | |
447 * Read data from the specified file. | |
448 * | |
449 * apr_file_read will read up to the specified number of | |
450 * bytes, but never more. If there isn't enough data to fill that | |
451 * number of bytes, all of the available data is read. The third | |
452 * argument is modified to reflect the number of bytes read. If a | |
453 * char was put back into the stream via ungetc, it will be the first | |
454 * character returned. | |
455 * | |
456 * It is not possible for both bytes to be read and an APR_EOF | |
457 * or other error to be returned. APR_EINTR is never returned. | |
458 * @param thefile The file descriptor to read from. | |
459 * @param buf The buffer to store the data to. | |
460 * @param offset Start offset in buf | |
461 * @param nbytes The number of bytes to read (-1) for full array. | |
462 * @return the number of bytes read. | |
463 */ | |
464 public static native int read(long thefile, byte[] buf, int offset, int nby
tes); | |
465 | |
466 /** | |
467 * Read data from the specified file. | |
468 * | |
469 * apr_file_read will read up to the specified number of | |
470 * bytes, but never more. If there isn't enough data to fill that | |
471 * number of bytes, all of the available data is read. The third | |
472 * argument is modified to reflect the number of bytes read. If a | |
473 * char was put back into the stream via ungetc, it will be the first | |
474 * character returned. | |
475 * | |
476 * It is not possible for both bytes to be read and an APR_EOF | |
477 * or other error to be returned. APR_EINTR is never returned. | |
478 * @param thefile The file descriptor to read from. | |
479 * @param buf The direct Byte buffer to store the data to. | |
480 * @param offset Start offset in buf | |
481 * @param nbytes The number of bytes to read. | |
482 * @return the number of bytes read. | |
483 */ | |
484 public static native int readb(long thefile, ByteBuffer buf, int offset, in
t nbytes); | |
485 | |
486 /** | |
487 * Read data from the specified file, ensuring that the buffer is filled | |
488 * before returning. | |
489 * | |
490 * Read will read up to the specified number of | |
491 * bytes, but never more. If there isn't enough data to fill that | |
492 * number of bytes, then the process/thread will block until it is | |
493 * available or EOF is reached. If a char was put back into the | |
494 * stream via ungetc, it will be the first character returned. | |
495 * | |
496 * It is possible for both bytes to be read and an error to be | |
497 * returned. And if *bytes_read is less than nbytes, an accompanying | |
498 * error is _always_ returned. | |
499 * | |
500 * APR_EINTR is never returned. | |
501 * @param thefile The file descriptor to read from. | |
502 * @param buf The buffer to store the data to. | |
503 * @param offset Start offset in buf | |
504 * @param nbytes The number of bytes to read (-1) for full array. | |
505 * @return the number of bytes read. | |
506 */ | |
507 public static native int readFull(long thefile, byte[] buf, int offset, int
nbytes); | |
508 | |
509 /** | |
510 * Read data from the specified file, ensuring that the buffer is filled | |
511 * before returning. | |
512 * | |
513 * Read will read up to the specified number of | |
514 * bytes, but never more. If there isn't enough data to fill that | |
515 * number of bytes, then the process/thread will block until it is | |
516 * available or EOF is reached. If a char was put back into the | |
517 * stream via ungetc, it will be the first character returned. | |
518 * | |
519 * It is possible for both bytes to be read and an error to be | |
520 * returned. And if *bytes_read is less than nbytes, an accompanying | |
521 * error is _always_ returned. | |
522 * | |
523 * APR_EINTR is never returned. | |
524 * @param thefile The file descriptor to read from. | |
525 * @param buf The direct ByteBuffer to store the data to. | |
526 * @param offset Start offset in buf | |
527 * @param nbytes The number of bytes to read. | |
528 * @return the number of bytes read. | |
529 */ | |
530 public static native int readFullb(long thefile, ByteBuffer buf, int offset
, int nbytes); | |
531 | |
532 /** | |
533 * Read a string from the specified file. | |
534 * The buffer will be NUL-terminated if any characters are stored. | |
535 * @param buf The buffer to store the string in. | |
536 * @param offset Start offset in buf | |
537 * @param thefile The file descriptor to read from | |
538 */ | |
539 public static native int gets(byte[] buf, int offset, long thefile); | |
540 | |
541 | |
542 /** | |
543 * Read a character from the specified file. | |
544 * @param thefile The file descriptor to read from | |
545 * @return The read character | |
546 */ | |
547 public static native int getc(long thefile) | |
548 throws Error; | |
549 | |
550 /** | |
551 * Are we at the end of the file | |
552 * @param fptr The apr file we are testing. | |
553 * @return Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwi
se. | |
554 */ | |
555 public static native int eof(long fptr); | |
556 | |
557 /** | |
558 * return the file name of the current file. | |
559 * @param thefile The currently open file. | |
560 */ | |
561 public static native String nameGet(long thefile); | |
562 | |
563 /** | |
564 * Set the specified file's permission bits. | |
565 * <br><b>Warning :</b> Some platforms may not be able to apply all of the | |
566 * available permission bits; APR_INCOMPLETE will be returned if some | |
567 * permissions are specified which could not be set. | |
568 * <br><b>Warning :</b> Platforms which do not implement this feature will r
eturn | |
569 * APR_ENOTIMPL. | |
570 * @param fname The file (name) to apply the permissions to. | |
571 * @param perms The permission bits to apply to the file. | |
572 * | |
573 */ | |
574 public static native int permsSet(String fname, int perms); | |
575 | |
576 /** | |
577 * Set attributes of the specified file. | |
578 * This function should be used in preference to explicit manipulation | |
579 * of the file permissions, because the operations to provide these | |
580 * attributes are platform specific and may involve more than simply | |
581 * setting permission bits. | |
582 * <br><b>Warning :</b> Platforms which do not implement this feature will r
eturn | |
583 * APR_ENOTIMPL. | |
584 * @param fname The full path to the file (using / on all systems) | |
585 * @param attributes Or'd combination of | |
586 * <PRE> | |
587 * APR_FILE_ATTR_READONLY - make the file readonly | |
588 * APR_FILE_ATTR_EXECUTABLE - make the file executable | |
589 * APR_FILE_ATTR_HIDDEN - make the file hidden | |
590 * </PRE> | |
591 * @param mask Mask of valid bits in attributes. | |
592 * @param pool the pool to use. | |
593 */ | |
594 public static native int attrsSet(String fname, int attributes, int mask, l
ong pool); | |
595 | |
596 /** | |
597 * Set the mtime of the specified file. | |
598 * <br><b>Warning :</b> Platforms which do not implement this feature will r
eturn | |
599 * APR_ENOTIMPL. | |
600 * @param fname The full path to the file (using / on all systems) | |
601 * @param mtime The mtime to apply to the file in microseconds | |
602 * @param pool The pool to use. | |
603 */ | |
604 public static native int mtimeSet(String fname, long mtime, long pool); | |
605 | |
606 /** | |
607 * Establish a lock on the specified, open file. The lock may be advisory | |
608 * or mandatory, at the discretion of the platform. The lock applies to | |
609 * the file as a whole, rather than a specific range. Locks are established | |
610 * on a per-thread/process basis; a second lock by the same thread will not | |
611 * block. | |
612 * @param thefile The file to lock. | |
613 * @param type The type of lock to establish on the file. | |
614 */ | |
615 public static native int lock(long thefile, int type); | |
616 | |
617 /** | |
618 * Remove any outstanding locks on the file. | |
619 * @param thefile The file to unlock. | |
620 */ | |
621 public static native int unlock(long thefile); | |
622 | |
623 /** | |
624 * Retrieve the flags that were passed into apr_file_open() | |
625 * when the file was opened. | |
626 * @param file The file to retrieve flags. | |
627 * @return the flags | |
628 */ | |
629 public static native int flagsGet(long file); | |
630 | |
631 /** | |
632 * Truncate the file's length to the specified offset | |
633 * @param fp The file to truncate | |
634 * @param offset The offset to truncate to. | |
635 */ | |
636 public static native int trunc(long fp, long offset); | |
637 | |
638 /** | |
639 * Create an anonymous pipe. | |
640 * @param io io[0] The file descriptors to use as input to the pipe. | |
641 * io[1] The file descriptor to use as output from the pipe. | |
642 * @param pool The pool to operate on. | |
643 */ | |
644 public static native int pipeCreate(long [] io, long pool); | |
645 | |
646 /** | |
647 * Get the timeout value for a pipe or manipulate the blocking state. | |
648 * @param thepipe The pipe we are getting a timeout for. | |
649 * @return The current timeout value in microseconds. | |
650 */ | |
651 public static native long pipeTimeoutGet(long thepipe) | |
652 throws Error; | |
653 | |
654 /** | |
655 * Set the timeout value for a pipe or manipulate the blocking state. | |
656 * @param thepipe The pipe we are setting a timeout on. | |
657 * @param timeout The timeout value in microseconds. Values < 0 mean | |
658 * wait forever, 0 means do not wait at all. | |
659 */ | |
660 public static native int pipeTimeoutSet(long thepipe, long timeout); | |
661 | |
662 /** | |
663 * Duplicate the specified file descriptor. | |
664 * @param newFile The file to duplicate. | |
665 * newFile must point to a valid apr_file_t, or point to NULL. | |
666 * @param oldFile The file to duplicate. | |
667 * @param pool The pool to use for the new file. | |
668 * @return Duplicated file structure. | |
669 */ | |
670 public static native long dup(long newFile, long oldFile, long pool) | |
671 throws Error; | |
672 | |
673 /** | |
674 * Duplicate the specified file descriptor and close the original. | |
675 * @param newFile The old file that is to be closed and reused. | |
676 * newFile MUST point at a valid apr_file_t. It cannot be NULL. | |
677 * @param oldFile The file to duplicate. | |
678 * @param pool The pool to use for the new file. | |
679 * @return Status code. | |
680 */ | |
681 public static native int dup2(long newFile, long oldFile, long pool); | |
682 | |
683 /** | |
684 * Get the specified file's stats. The file is specified by filename, | |
685 * instead of using a pre-opened file. | |
686 * @param finfo Where to store the information about the file, which is | |
687 * never touched if the call fails. | |
688 * @param fname The name of the file to stat. | |
689 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values | |
690 * @param pool the pool to use to allocate the new file. | |
691 */ | |
692 public static native int stat(FileInfo finfo, String fname, int wanted, long
pool); | |
693 | |
694 /** | |
695 * Get the specified file's stats. The file is specified by filename, | |
696 * instead of using a pre-opened file. | |
697 * @param fname The name of the file to stat. | |
698 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values | |
699 * @param pool the pool to use to allocate the new file. | |
700 * @return FileInfo object. | |
701 */ | |
702 public static native FileInfo getStat(String fname, int wanted, long pool); | |
703 | |
704 /** | |
705 * Get the specified file's stats. | |
706 * @param finfo Where to store the information about the file. | |
707 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values | |
708 * @param thefile The file to get information about. | |
709 */ | |
710 public static native int infoGet(FileInfo finfo, int wanted, long thefile); | |
711 | |
712 | |
713 /** | |
714 * Get the specified file's stats. | |
715 * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_
values | |
716 * @param thefile The file to get information about. | |
717 * @return FileInfo object. | |
718 */ | |
719 public static native FileInfo getInfo(int wanted, long thefile); | |
720 | |
721 } | |
OLD | NEW |