author | aefimov |
Fri, 10 Apr 2015 14:54:20 +0300 | |
changeset 29839 | 6d5d546e953b |
parent 25871 | b80b84e87032 |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
29839
6d5d546e953b
8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
25871
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
12009 | 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.nio.ByteBuffer; |
|
29 |
import java.io.File; |
|
30 |
import java.io.IOException; |
|
16791 | 31 |
import java.util.logging.Level; |
12009 | 32 |
import java.util.logging.Logger; |
33 |
||
34 |
/** |
|
35 |
* Keeps the Part's partial content data in memory. |
|
36 |
* |
|
37 |
* @author Kohsuke Kawaguchi |
|
38 |
* @author Jitendra Kotamraju |
|
39 |
*/ |
|
40 |
final class MemoryData implements Data { |
|
41 |
private static final Logger LOGGER = Logger.getLogger(MemoryData.class.getName()); |
|
42 |
||
43 |
private final byte[] data; |
|
44 |
private final int len; |
|
45 |
private final MIMEConfig config; |
|
46 |
||
47 |
MemoryData(ByteBuffer buf, MIMEConfig config) { |
|
48 |
data = buf.array(); |
|
49 |
len = buf.limit(); |
|
50 |
this.config = config; |
|
51 |
} |
|
52 |
||
53 |
// size of the chunk given by the parser |
|
16791 | 54 |
@Override |
12009 | 55 |
public int size() { |
56 |
return len; |
|
57 |
} |
|
58 |
||
16791 | 59 |
@Override |
12009 | 60 |
public byte[] read() { |
61 |
return data; |
|
62 |
} |
|
63 |
||
16791 | 64 |
@Override |
12009 | 65 |
public long writeTo(DataFile file) { |
66 |
return file.writeTo(data, 0, len); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* |
|
71 |
* @param dataHead |
|
72 |
* @param buf |
|
73 |
* @return |
|
74 |
*/ |
|
16791 | 75 |
@Override |
12009 | 76 |
public Data createNext(DataHead dataHead, ByteBuffer buf) { |
77 |
if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) { |
|
78 |
try { |
|
79 |
String prefix = config.getTempFilePrefix(); |
|
80 |
String suffix = config.getTempFileSuffix(); |
|
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
81 |
File tempFile = TempFiles.createTempFile(prefix, suffix, config.getTempDir()); |
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
82 |
// delete the temp file when VM exits as a last resort for file clean up |
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
83 |
tempFile.deleteOnExit(); |
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
84 |
if (LOGGER.isLoggable(Level.FINE)) { |
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
85 |
LOGGER.log(Level.FINE, "Created temp file = {0}", tempFile); |
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
86 |
} |
12009 | 87 |
dataHead.dataFile = new DataFile(tempFile); |
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
88 |
} catch (IOException ioe) { |
12009 | 89 |
throw new MIMEParsingException(ioe); |
90 |
} |
|
91 |
||
92 |
if (dataHead.head != null) { |
|
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
93 |
for (Chunk c = dataHead.head; c != null; c = c.next) { |
12009 | 94 |
long pointer = c.data.writeTo(dataHead.dataFile); |
95 |
c.data = new FileData(dataHead.dataFile, pointer, len); |
|
96 |
} |
|
97 |
} |
|
98 |
return new FileData(dataHead.dataFile, buf); |
|
99 |
} else { |
|
100 |
return new MemoryData(buf, config); |
|
101 |
} |
|
102 |
} |
|
18372
4d90cbb0d70a
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents:
16791
diff
changeset
|
103 |
|
12009 | 104 |
} |