src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/mimepull/DataFile.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.org.jvnet.mimepull;
27
28 import java.io.*;
29
30 /**
31 * Use {@link RandomAccessFile} for concurrent access of read
32 * and write partial part's content.
33 *
34 * @author Kohsuke Kawaguchi
35 * @author Jitendra Kotamraju
36 */
37 final class DataFile {
38 private WeakDataFile weak;
39 private long writePointer;
40
41 DataFile(File file) {
42 writePointer=0;
43 weak = new WeakDataFile(this, file);
44 }
45
46 /**
47 *
48 */
49 void close() {
50 weak.close();
51 }
52
53 /**
54 * Read data from the given file pointer position.
55 *
56 * @param pointer read position
57 * @param buf that needs to be filled
58 * @param offset the start offset of the data.
59 * @param length of data that needs to be read
60 */
61 synchronized void read(long pointer, byte[] buf, int offset, int length ) {
62 weak.read(pointer, buf, offset, length);
63 }
64
65 void renameTo(File f) {
66 weak.renameTo(f);
67 }
68
69 /**
70 * Write data to the file
71 *
72 * @param data that needs to written to a file
73 * @param offset start offset in the data
74 * @param length no bytes to write
75 * @return file pointer before the write operation(or at which the
76 * data is written)
77 */
78 synchronized long writeTo(byte[] data, int offset, int length) {
79 long temp = writePointer;
80 writePointer = weak.writeTo(writePointer, data, offset, length);
81 return temp;
82 }
83
84 }

mercurial