MCPcopy Create free account
hub / github.com/GateNLP/gate-core / writeTempFile

Method writeTempFile

src/main/java/gate/util/Files.java:192–217  ·  view source on GitHub ↗

Writes a temporary file into the default temporary directory, form an InputStream a unique ID is generated and associated automaticaly with the file name...

(InputStream contentStream)

Source from the content-addressed store, hash-verified

190 * with the file name...
191 */
192 public static File writeTempFile(InputStream contentStream)
193 throws IOException {
194
195 File resourceFile = null;
196 FileOutputStream resourceFileOutputStream = null;
197
198 try {
199 // create a temporary file name
200 resourceFile = File.createTempFile("gateResource", ".tmp");
201 resourceFileOutputStream = new FileOutputStream(resourceFile);
202 resourceFile.deleteOnExit();
203
204 if(contentStream == null) return resourceFile;
205
206 int bytesRead = 0;
207 final int readSize = 1024;
208 byte[] bytes = new byte[readSize];
209 while((bytesRead = contentStream.read(bytes, 0, readSize)) != -1)
210 resourceFileOutputStream.write(bytes, 0, bytesRead);
211 } finally {
212 IOUtils.closeQuietly(resourceFileOutputStream);
213 IOUtils.closeQuietly(contentStream);
214 }
215
216 return resourceFile;
217 }// writeTempFile()
218
219 /**
220 * Writes aString into a temporary file located inside

Callers 5

testWriteTempFileMethod · 0.95
testUpdateXmlElementMethod · 0.95
convertMethod · 0.95

Calls 4

readMethod · 0.65
closeMethod · 0.65
writeMethod · 0.45
flushMethod · 0.45

Tested by 4

testWriteTempFileMethod · 0.76
testUpdateXmlElementMethod · 0.76