@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; } /**
/** */ private String getClue(FileContents fc, URL source) { if (fc != null) try { return fc.getName(); } catch (IOException x) {} // just fall through: failure _is_ an option in this case if (source != null) return source.getPath(); return "worksheet.hwks"; }
@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); } }
/** * Loads the file via the JNLP FileOpen service */ public int loadFile(Spreadsheet sheet) { final Controller controller = getController(); try { FileOpenService fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService"); if (fos == null) { return Controller.CANCEL_OPTION; } // ask user to select a file through this service _fc = fos.openFileDialog(null, null); if (_fc == null) return Controller.CANCEL_OPTION; sheet.readSpreadsheet(_fc.getInputStream()); controller.setSheetSource(new URL("file:///"+_fc.getName())); controller.setSheetDirty(false); return Controller.YES_OPTION; } catch (Exception x) { displayError(x); return Controller.CANCEL_OPTION; } }
fc.getMaxLength(); // This will throw an exception if there is no muffin yet. } catch (Exception ex) { fc = null; OutputStream os = fc.getOutputStream(false); byte[] buf = strValue.getBytes(ENCODING); os.write(buf);
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); } }
/** * Open this file. * @return */ public InputStream openFileStream(String pathHint, String[] extensions) { if (fos == null) { try { fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService"); } catch (UnavailableServiceException e) { fos = null; } } if (fos != null) { try { // ask user to select a file through this service FileContents fc = fos.openFileDialog(pathHint, extensions); return fc.getInputStream(); } catch (Exception e) { e.printStackTrace(); } } return null; }
controller.setSheetSource(new URL("file:///"+_fc.getName())); controller.setSheetDirty(false); pipeIn.close();
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 configURL = new URL(baseURL, fileName); FileContents fc = ps.get(configURL); DataInputStream ois = new DataInputStream(fc.getInputStream());