File: serialize.R

package info (click to toggle)
rjava 1.0-11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,184 kB
  • sloc: java: 13,223; ansic: 5,479; sh: 3,776; xml: 325; makefile: 250; 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))
}