public Object getFileAsBytes(String name, OC out, boolean allowZip) { // ?? used by eval of "WRITE FILE" // will be full path name if (name == null) return null; String fullName = name; String[] subFileList = null; if (name.indexOf("|") >= 0) { subFileList = PT.split(name, "|"); name = subFileList[0]; allowZip = true; } Object t = getBufferedInputStreamOrErrorMessageFromName(name, fullName, false, false, null, false); if (t instanceof String) return "Error:" + t; try { BufferedInputStream bis = (BufferedInputStream) t; Object bytes = (out != null || !allowZip || subFileList == null || subFileList.length <= 1 || !JmolBinary.isZipS(bis) && !JmolBinary.isPngZipStream(bis) ? JmolBinary.getStreamAsBytes(bis, out) : JmolBinary.getZipFileContentsAsBytes(bis, subFileList, 1)); bis.close(); return bytes; } catch (Exception ioe) { return ioe.toString(); } }
@Override public String postByteArray(String fileName, byte[] bytes) { Object ret = getBufferedInputStreamOrErrorMessageFromName(fileName, null, false, false, bytes, false); if (ret instanceof String) return (String) ret; try { ret = JmolBinary.getStreamAsBytes((BufferedInputStream) ret, null); } catch (IOException e) { try { ((BufferedInputStream) ret).close(); } catch (IOException e1) { // ignore } } return (ret == null ? "" : JmolBinary.fixUTF((byte[]) ret)); }