Project

General

Profile

« Previous | Next » 

Revision 9599

Added by Jing Tao over 8 years ago

Close the the input stream from the method parameter in the create method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1306 1306
   * @return localId - the resulting docid of the document created or updated
1307 1307
   * 
1308 1308
   */
1309
  public String insertOrUpdateDocument(InputStream xml, String encoding,  Identifier pid, 
1309
  public String insertOrUpdateDocument(InputStream xmlStream, String encoding,  Identifier pid, 
1310 1310
    Session session, String insertOrUpdate, String formatId) 
1311 1311
    throws ServiceFailure, IOException {
1312 1312
    
......
1315 1315

  
1316 1316
    // generate pid/localId pair for sysmeta
1317 1317
    String localId = null;
1318
    byte[] xmlBytes  = IOUtils.toByteArray(xml);
1318
    byte[] xmlBytes  = IOUtils.toByteArray(xmlStream);
1319
    IOUtils.closeQuietly(xmlStream);
1319 1320
    String xmlStr = new String(xmlBytes, encoding);
1320 1321
    if(insertOrUpdate.equals("insert")) {
1321 1322
      localId = im.generateLocalId(pid.getValue(), 1);
......
1872 1873
   * 
1873 1874
   * @throws ServiceFailure
1874 1875
   */
1875
  private File writeStreamToFile(File dir, String fileName, InputStream data) 
1876
  private File writeStreamToFile(File dir, String fileName, InputStream dataStream) 
1876 1877
    throws ServiceFailure {
1877 1878
    
1878 1879
    File newFile = new File(dir, fileName);
......
1882 1883
        if (newFile.createNewFile()) {
1883 1884
          // write data stream to desired file
1884 1885
          OutputStream os = new FileOutputStream(newFile);
1885
          long length = IOUtils.copyLarge(data, os);
1886
          long length = IOUtils.copyLarge(dataStream, os);
1886 1887
          os.flush();
1887 1888
          os.close();
1888 1889
        } else {
......
1897 1898
      logMetacat.debug("IOE: " + e.getMessage());
1898 1899
      throw new ServiceFailure("1190", "File was not written: " + fileName 
1899 1900
                + " " + e.getMessage());
1901
    } finally {
1902
        IOUtils.closeQuietly(dataStream);
1900 1903
    }
1901 1904

  
1902 1905
    return newFile;

Also available in: Unified diff