Project

General

Profile

Feature #4170

R D1Object.getData() should allow access to binary data

Added by Ben Leinfelder almost 11 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
2013-11-08
Due date:
2014-09-10
% Done:

100%

Milestone:
None
Story Points:
Sprint:

Description

Current implementation converts the byte[] to a UTF-8 String. This is only appropriate for text-based data, of course, but not for a ZIP file.

Worked up a work-around for Sarah Clark and the GulfWatch project by overriding the getData method as below (taken from https://repository.dataone.org/software/cicore/trunk/itk/d1_client_r/dataone/R/D1Object-methods.R).

setMethod("getData", signature("D1Object"), function(x, fileName=NA) {
jD1Object = x@jD1o
if(!is.jnull(jD1Object)) {
databytes <- jD1Object$getData()
if(is.null(databytes)) {
print(paste("Didn't find data in:", id))
return()
}

    if (!is.na(fileName)) {
        ## Write data to file
        jFileOutputStream <- .jnew("java/io/FileOutputStream", fileName)
        jInputStream <- .jnew("java/io/ByteArrayInputStream", databytes)
        ioUtils <- .jnew("org/apache/commons/io/IOUtils")
        ioUtils$copy(jInputStream, jFileOutputStream)
        returnVal = fileName
    } else {
        ## return data as string
        jDataString <- .jnew("java/lang/String",databytes,"UTF-8")
        if (!is.null(e<-.jgetEx())) {
            print("Java exception was raised")
            print(e)
            print(.jcheck(silent=FALSE))
        }
        dataString <- jDataString$toString()
        returnVal = dataString
    }

    return(returnVal)
}

})

History

#1 Updated by Matthew Jones about 10 years ago

  • Due date changed from 2013-11-08 to 2014-09-10
  • Status changed from New to Closed

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 14.8 MB)