public PyObject load() { try { PyObject obj = read_object(0); if (obj == null) { throw Py.TypeError("NULL object in marshal data"); } return obj; } catch (StringIndexOutOfBoundsException e) { // convert from our PyIOFile abstraction to what marshal in CPython returns // (although it's really just looking for no bombing) throw Py.EOFError("EOF read where object expected"); } }
@Override public int readinto(ByteBuffer buf) { int bytesRead = 0; try { bytesRead = super.readinto(buf); } catch (PyException pyex) { // translate errors on read of decompressed stream to EOFError throw Py.EOFError(pyex.value.asStringOrNull()); } position += bytesRead; return bytesRead; }
/** * Companion to <code>raw_input</code> built-in function used when the interactive interpreter * is directed to a file. * * @param prompt to issue at console before read * @param file a file-like object to read from * @return line of text from the file (encoded as bytes values compatible with PyString) */ public static String raw_input(PyObject prompt, PyObject file) { PyObject stdout = Py.getSystemState().stdout; if (stdout instanceof PyAttributeDeleted) { throw Py.RuntimeError("[raw_]input: lost sys.stdout"); } Py.print(stdout, prompt); String data = readline(file).toString(); if (data.endsWith("\n")) { return data.substring(0, data.length() - 1); } else { if (data.length() == 0) { throw Py.EOFError("raw_input()"); } } return data; }
private void makeReadBuffer() { try { FileInputStream fin = new FileInputStream(fileName); BufferedInputStream bin = new BufferedInputStream(fin); BZip2CompressorInputStream bZin = new BZip2CompressorInputStream( bin, true); BufferedReader bufferedReader = new BufferedReader( new SkippableStreamIO(bZin, true), buffering); if (inUniversalNewlineMode) { buffer = new UniversalIOWrapper(bufferedReader); } else { buffer = new BinaryIOWrapper(bufferedReader); } } catch (FileNotFoundException fileNotFoundException) { throw Py.IOError(fileNotFoundException); } catch (IOException ioe) { throw Py.EOFError(ioe.getMessage()); } }
throw Py.EOFError("Data stream EOF reached");
throw Py.EOFError("not enough items in file. " + Integer.toString(count) + " requested, " + Integer.toString(readcount) + " actually read");
/** * Shorthand function which unpickles a object from the file and returns * the new object. * @param file a file-like object, can be a cStringIO.StringIO, * a PyFile or any python object which implements a * <i>read</i> and <i>readline</i> method. * @return a new object. */ public static Object load(PyObject file) { try { return new Unpickler(file).load(); } catch (ArrayIndexOutOfBoundsException e) { // invalid data, bad stack throw Py.IndexError(e.getMessage()); } catch (StringIndexOutOfBoundsException e) { // short data throw Py.EOFError(e.getMessage()); } }
throw Py.EOFError("not enough items in string");