File: serialize.R

package info (click to toggle)
rjava 0.9-3-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,196 kB
  • sloc: java: 7,733; ansic: 4,947; sh: 2,878; makefile: 137; perl: 33
file content (29 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Java serialization/unserialization

.jserialize <- function(o) {
  if (!is(o, "jobjRef"))
    stop("can serialize Java objects only")
  .jcall("RJavaClassLoader","[B","toByte",.jcast(o, "java.lang.Object"))
}

.junserialize <- function(data) {
  if (!is.raw(data))
    stop("can de-serialize raw vectors only")
  o <- .jcall("RJavaClassLoader","Ljava/lang/Object;","toObjectPL",.jarray(data, dispatch = FALSE))
  if (!is.jnull(o)) {
    cl<-try(.jclass(o), silent=TRUE)
    if (all(class(cl) == "character"))
      o@jclass <- gsub("\\.","/",cl)
  }
  o
}

.jcache <- function(o, update=TRUE) {
  if (!is(o, "jobjRef"))
    stop("o must be a Java object")
  if (!is.null(update) && (!is.logical(update) || length(update) != 1))
    stop("update must be TRUE, FALSE of NULL")
  what <- update
  if (isTRUE(what)) what <- .jserialize(o)
  invisible(.Call(javaObjectCache, o@jobj, what))
}