private int handleClose(int a0) { OpenFile file = openfiles.get(a0); if (file == null) return -1; file.close(); openfiles.remove(a0); available_descriptors.add(a0); return 0; }
public void importFile() { Editor editor=getJPE().getEditor(); String tempfilename = getFileName(FileDialog.LOAD); OpenFile tempfile = new OpenFile(tempfilename); String txt = tempfile.getText(); if (txt != null) { editor.insertText(txt); getJPE().say("Text Import"); } }
private void handleClose(String result) { // get the text handler Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { // get the selected file from the text handler OpenFile file=editor.getEditFile(); if (file!=null) { if (result.equals("y")) file.saveFile(); file.clearDirty(); closeFile(); } } }
/** * save selected file to disk */ private void saveFile() { // get the text handler Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { // get the selected file from the text handler OpenFile file=editor.getEditFile(); if (file!=null) { // signal the use we are saving and save it to disk getJPE().say("Saving file "+file.getName()); file.saveFile(); getJPE().say("Saved file "+file.getName()); } } }
/** * close the selected file, meaning removing it from the Opened * list and removing it from the auto reload on startup list */ private void closeFile() { OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { OpenFile file=editor.getEditFile(); if (!file.isDirty()) { ofh.removeFile(file); addRecent(file.getName()); ofh.switchOpenFile(); } else { getJPE().setAskMode(this,"close","File not saved, save first (y/n) ? ",true); } } }
public void handleRevert(String answer) { if("y".equals(answer)) { Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { // get the selected file from the text handler OpenFile file=editor.getEditFile(); if (file!=null) { // revert the file file.loadFile(); // tell editor to useFile, without saving editor.useFile(file,false); } } } }
@Override public String getName() { String ret = mFile.getName(); if (ret.endsWith("/")) ret = ret.substring(0, ret.length() - 1); ret = ret.substring(ret.lastIndexOf("/") + 1); return ret; }
/* we will try to allocate a free page from the freepages*/ public static int insertPage(int ppn) { int numBits = 0; int spn = swapFile.length() / PAGESIZE; if (freePages.size() > 0) { spn = freePages.remove(0); } return insertPage(spn, ppn); }
public static int insertPage(int spn, int ppn) { swapLock.acquire(); int numBits = swapFile.write(spn * PAGESIZE, memory, ppn * PAGESIZE, PAGESIZE); // assert that numBits == PAGESIZE allocatedPages.add(spn); swapLock.release(); return spn; }
private void lockFile() { OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); Editor editor=(Editor)getJPE().getEditor(); if (editor!=null) { OpenFile file=editor.getEditFile(); if (file.isLocked()) { file.clearLocked(); getJPE().setLockState(false); getJPE().say("file is now unlocked ( read / write )"); } else { file.setLocked(); getJPE().setLockState(true); getJPE().say("file is now locked (read only)"); } ofh.updateProperties(); } }
public static void readPage(int spn, int ppn) { if (allocatedPages.contains(spn)) { swapLock.acquire(); swapFile.read(spn * PAGESIZE, memory, ppn * PAGESIZE, PAGESIZE); swapLock.release(); } else { } }
/** * create new file, under the name untitled or a followup * untitled2, untitled3 etc etc */ public void newFile(boolean template) { // get the openfile handler to add the new file OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); if (ofh==null) { // no opened handler started so lets start one and add it the // menu. ofh=(OpenFileHandler)getJPE().addHandler(new OpenFileHandler(getJPE())); ofh.createMenu(getJPE().getMenuBar()); } // find a empty untitled filename String prefix="untitled"; String filename=prefix; int i=2; // repeat until we found one while (ofh.isLoaded(filename)) { filename=prefix+(i++); } // open a file with the found name OpenFile file=new OpenFile(filename); if(template) { // open a dialog to let the user select the file we need to load String tempfilename = getFileName(FileDialog.LOAD); OpenFile tempfile = new OpenFile(tempfilename); String txt = tempfile.getText(); try { RE re = new RE("<getJPE():date>"); txt = re.substitute(txt,""+new Date()); file.setText(txt); } catch(REException ree) { ree.printStackTrace(); } } // add the file to the opened file list ofh.addFile(file); // load this file into the text area getJPE().getEditor().useFile(file); }
public void fetchFrom(OpenFile file) { byte buffer[] = new byte[tableSize * DirectoryEntry.sizeOf()]; // read the file file.readAt(buffer, 0, tableSize * DirectoryEntry.sizeOf(), 0); // unmarshall int pos = 0; for (int i = 0; i < tableSize; i++) { table[i].internalize(buffer, pos); pos += DirectoryEntry.sizeOf(); } }
public void writeBack(OpenFile file) { byte buffer[] = new byte[tableSize * DirectoryEntry.sizeOf()]; // marshall int pos = 0; for (int i = 0; i < tableSize; i++) { table[i].externalize(buffer, pos); pos += DirectoryEntry.sizeOf(); } // write the file file.writeAt(buffer, 0, tableSize * DirectoryEntry.sizeOf(), 0); }
public OpenLZMA(OpenFile file) { mFile = file; try { mRAF = new MyRandomAccessFile(file.getPath(), "r"); mLZMA = new Handler(); mLZMA.Open(mRAF); // Logger.LogInfo("LZMA file " + LZMAFile + " has " + length() + // " entries"); } catch (IOException e) { Logger.LogError("Couldn't open LZMA file (" + file + ")"); } }
private int handleWrite(int a0, int bufaddr, int count) { OpenFile file = openfiles.get(a0); if (file == null) return -1; byte[] transfer_buffer = new byte[Processor.pageSize]; int total_transfer = 0; while (count > 0) { int readlen = Math.min(Processor.pageSize, count); int actualread = readVirtualMemory(bufaddr, transfer_buffer, 0, readlen); if (actualread == -1) return -1; if (actualread < readlen) return -1; int written_bytes = file.write(transfer_buffer, 0, actualread); if (written_bytes != actualread) { return -1; } count -= actualread; bufaddr += actualread; total_transfer += actualread; } return total_transfer; }
/** * ask the user for a filename (using a file requester) and save * the current file under that name */ private void saveAsFile() { // get openfile handlers OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened"); if (ofh!=null) { // ask the user for the file name String filename=getFileName(FileDialog.SAVE); // get the text handler Editor editor=(Editor)getJPE().getEditor(); // get the selected file OpenFile file=editor.getEditFile(); // remove the file from the opened list ofh.removeFile(file); if (file!=null) { // set the new name in the file file.setName(filename); getJPE().say("Saving file "+file.getName()); // save the file under this new name file.saveFile(); // add the file to the opened files again (now new name) ofh.addFile(file); getJPE().say("Saved file "+file.getName()); } } }
/** * Sets the properties of a new task, passed as an argument. * * <p>Creates a new thread list, sets TaskLive status and creation time, creates and opens the * task's swap file of the size equal to the size (in bytes) of the addressable virtual memory. * * @return task or null @OSPProject Tasks */ public static TaskCB do_create() { TaskCB new_task = new TaskCB(); // criação da nova task HClock new_clock = new HClock(); // instância do relógio do sistema String path = SwapDeviceMountPoint + String.valueOf(new_task.getID()); // path do swap file new_task.new_thread = new ArrayList<ThreadCB>(); new_task.new_port = new ArrayList<PortCB>(); new_task.new_file = new ArrayList<OpenFile>(); new_task.setPageTable(new PageTable(new_task)); new_task.setCreationTime( new_clock.get()); // usa a instância do relógio, para setar o horário de criação da task new_task.setStatus(TaskLive); // seta o estado atual da task (TaskLive) new_task.setPriority(1); // como não foi especificado nenhuma prioridade na descrição, usamos 1 new_task.new_swap.create( path, (int) Math.pow( 2.0D, MMU.getVirtualAddressBits())); // tamanho da página deve ser 2^(número de bits do // ambiente) OpenFile save_swap = OpenFile.open(path, new_task); // abrimos o swap file new_task.setSwapFile( save_swap); // dizemos que o swap criado acima deve ser alocado a nossa task ThreadCB.create(new_task); // criamos a thread inicial if (save_swap == null) { // verificamos se o swap foi criado com sucesso new_task .new_thread .get(0) .dispatch(); // caso não tenha, dispachamos a thread criada acima (posição 0 do vetor) return null; // e retornamos uma task nula } return new_task; // se tudo ocorreu como esperado, retornamos a task criada inicialmente }
@Override public OpenPath getParent() { return mFile.getParent(); }
@Override public String getAbsolutePath() { return mFile.getAbsolutePath(); }
@Override public long length() { return mFile.length(); }
@Override public Long lastModified() { return mFile.lastModified(); }
@Override public String getPath() { return mFile.getPath(); }
@Override public OutputStream getOutputStream() throws IOException { return new LzmaOutputStream(mFile.getOutputStream()); }
@Override public Boolean canRead() { return mFile.canRead(); }
@Override public InputStream getInputStream() throws IOException { return new LzmaInputStream(mFile.getInputStream()); }
@Override public Boolean mkdir() { return mFile.mkdir(); }
@Override public Boolean delete() { return mFile.delete(); }
@Override public Boolean exists() { return mFile.exists(); }
@Override public Boolean canWrite() { return mFile.canWrite(); }