@Override public InputStream openInputFile(String fileName) throws IOException { checkBasics("openInputFile"); URL fileURL = fileNameToURL(fileName); try { return new BufferedInputStream(ps.get(fileURL).getInputStream()); } catch (Exception e) { throw new IOException("openInputFile \"" + fileName + "\" failed", e); } }
/** * Get the current value for this muffin. * @param strParam The key for this muffin parameter. * @return The value for this muffin (null if none). */ public String getMuffin(String strParam) { try { URL url = new URL(m_strCodeBase + strParam); FileContents fc = m_ps.get(url); if (fc == null) return null; // read in the contents of a muffin byte[] buf = new byte[(int)fc.getLength()]; InputStream is = fc.getInputStream(); int pos = 0; while((pos = is.read(buf, pos, buf.length - pos)) > 0) { // just loop } is.close(); String strValue = new String(buf, ENCODING); return strValue; } catch (Exception ex) { // Return null for any exception } return null; } /**
@Override public OutputStream openOutputFile(String fileName, boolean append) throws IOException { checkBasics("openOutputFile"); URL fileURL = fileNameToURL(fileName); try { FileContents fc = null; try { fc = ps.get(fileURL); } catch (FileNotFoundException e) { /* Verify that the max size for new PersistenceService * files is >= 100K (2^17) before opening one. */ long maxSizeRequest = 131072L; long maxSize = ps.create(fileURL, maxSizeRequest); if (maxSize >= maxSizeRequest) { fc = ps.get(fileURL); } } if ((fc != null) && (fc.canWrite())) { return new BufferedOutputStream(fc.getOutputStream(!append)); } else { throw new IOException("unable to create FileContents object"); } } catch (Exception e) { throw new IOException("openOutputFile \"" + fileName + "\" failed", e); } }
public InputStream openInputFile(String fileName) throws IOException { checkBasics("openInputFile"); URL fileURL = fileNameToURL(fileName); try { return new BufferedInputStream(ps.get(fileURL).getInputStream()); } catch(Exception e) { throw new LSException("openInputFile \"" + fileName + "\" failed", e); } }
URL baseURL = bs.getCodeBase(); URL configURL = new URL(baseURL, fileName); FileContents fc = ps.get(configURL); DataInputStream ois = new DataInputStream(fc.getInputStream());
public OutputStream openOutputFile(String fileName) throws IOException { checkBasics("openOutputFile"); URL fileURL = fileNameToURL(fileName); try { FileContents fc = null; try { fc = ps.get(fileURL); } catch (FileNotFoundException e) { /* Verify that the max size for new PersistenceService * files is >= 100K (2^17) before opening one. */ long maxSizeRequest = 131072L; long maxSize = ps.create(fileURL, maxSizeRequest); if (maxSize >= maxSizeRequest) { fc = ps.get(fileURL); } } if ((fc != null) && (fc.canWrite())) { return new BufferedOutputStream(fc.getOutputStream(true)); } else { throw new IOException("unable to create FileContents object"); } } catch(Exception e) { throw new LSException("openOutputFile \"" + fileName + "\" failed", e); } }
ps.create(configURL, 1024); // 1024 bytes for our data FileContents fc = ps.get(configURL); DataOutputStream oos = new DataOutputStream(fc .getOutputStream(false));