final void file_truncate() { try { file.truncate(file.tell()); } catch (IOException e) { throw Py.IOError(e); } }
public int read() throws IOException { int c = file.read(); if (c != '\r') return c; if (file.available() > 0) { c = file.read(); if (c != -1 && c != '\n') file.unread(c); } return '\n'; }
public Set<String> getFiles() { final Set<String> result = new HashSet<String>(); for (FileWrapper f : mySources.keySet()) { result.add(f.getName()); } return result; }
private String expectAssetIn(String assetFilename, File directory) { String[] dirs = assetFilename.split("/"); File currentDir = directory; for (int i = 0; i < dirs.length - 1; i++) { currentDir = new File(currentDir, dirs[i]); } currentDir.mkdirs(); File file = new File(currentDir, dirs[dirs.length - 1]); FileWrapper fileWrapper = new FileWrapper(file); fileWrapper.writeString(assetFilename, false); return file.getAbsolutePath(); }
public Set<String> getRemovedFiles(final Properties past) { final Set<String> result = new HashSet<String>(); if (past != null) { for (FileWrapper was : past.mySources.keySet()) { final FileWrapper now = mySources.get(was); if (now == null) { result.add(was.getName()); } } } return result; }
/** Returns an HttpEntity containing all request parameters */ public HttpEntity getEntity() { HttpEntity entity = null; if (!fileParams.isEmpty()) { SimpleMultipartEntity multipartEntity = new SimpleMultipartEntity(); // Add string params for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) { multipartEntity.addPart(entry.getKey(), entry.getValue()); } // Add dupe params for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) { ArrayList<String> values = entry.getValue(); for (String value : values) { multipartEntity.addPart(entry.getKey(), value); } } // Add file params int currentIndex = 0; int lastIndex = fileParams.entrySet().size() - 1; for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) { FileWrapper file = entry.getValue(); if (file.inputStream != null) { boolean isLast = currentIndex == lastIndex; if (file.contentType != null) { multipartEntity.addPart( entry.getKey(), file.getFileName(), file.inputStream, file.contentType, isLast); } else { multipartEntity.addPart(entry.getKey(), file.getFileName(), file.inputStream, isLast); } } currentIndex++; } entity = multipartEntity; } else { try { entity = new UrlEncodedFormEntity(getParamsList(), ENCODING); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return entity; }
final void file_truncate(long position) { try { file.truncate(position); } catch (IOException e) { throw Py.IOError(e); } }
final void file_flush() { if (closed) err_closed(); try { file.flush(); } catch (IOException e) { throw Py.IOError(e); } }
final void file_seek(long pos, int how) { if (closed) err_closed(); try { file.seek(pos, how); } catch (IOException e) { throw Py.IOError(e); } }
final long file_tell() { if (closed) err_closed(); try { return file.tell(); } catch (IOException e) { throw Py.IOError(e); } }
final void file_write(String s) { if (closed) err_closed(); try { file.write(s); softspace = false; } catch (IOException e) { throw Py.IOError(e); } }
public Object __tojava__(Class cls) { Object o = null; try { o = file.__tojava__(cls); } catch (IOException exc) { } if (o == null) o = super.__tojava__(cls); return o; }
public void truncate(long position) throws IOException { flush(); try { // file.setLength(position); java.lang.reflect.Method m = file.getClass().getMethod("setLength", new Class[] {Long.TYPE}); m.invoke(file, new Object[] {new Long(position)}); } catch (NoSuchMethodException exc) { super.truncate(position); } catch (SecurityException exc) { super.truncate(position); } catch (IllegalAccessException exc) { super.truncate(position); } catch (java.lang.reflect.InvocationTargetException exc) { if (exc.getTargetException() instanceof IOException) throw (IOException) exc.getTargetException(); super.truncate(position); } }
private void file_init(FileWrapper file, String name, String mode) { file.setMode(mode); this.name = name; this.mode = mode; this.softspace = false; this.closed = false; if (mode.indexOf('b') < 0) { this.file = new TextWrapper(file); } else { this.file = file; } }
public String read(int n) throws IOException { String s = this.file.read(n); int index = s.indexOf('\r'); if (index < 0) return s; StringBuffer buf = new StringBuffer(); int start = 0; int end = s.length(); do { buf.append(s.substring(start, index)); buf.append('\n'); start = index + 1; if (start < end && s.charAt(start) == '\n') start++; index = s.indexOf('\r', start); } while (index >= 0); buf.append(s.substring(start)); if (s.endsWith("\r") && file.available() > 0) { int c = file.read(); if (c != -1 && c != '\n') file.unread(c); } return buf.toString(); }
final void file_close() { if (closer != null) { closer.close(); closer = null; } else { try { file.close(); } catch (IOException e) { throw Py.IOError(e); } } closed = true; file = new FileWrapper(); }
final String file_readline(int max) { if (closed) err_closed(); StringBuffer s = new StringBuffer(); while (max < 0 || s.length() < max) { int c; try { c = file.read(); } catch (IOException e) { throw Py.IOError(e); } if (c < 0) break; s.append((char) c); if ((char) c == '\n') break; } return s.toString(); }
final String file_read(int n) { if (closed) err_closed(); StringBuffer data = new StringBuffer(); try { while (n != 0) { String s = file.read(n); int len = s.length(); if (len == 0) break; data.append(s); if (n > 0) { n -= len; if (n <= 0) break; } } } catch (IOException e) { throw Py.IOError(e); } return data.toString(); }
public Set<String> getOutdatedFiles(final Properties past) { final Set<String> result = new HashSet<String>(); for (FileWrapper now : mySources.keySet()) { final FileWrapper than = past == null ? null : past.mySources.get(now); if (than == null || than.getStamp() < now.getStamp() || affectedFiles.contains(now.getName())) { result.add(now.getName()); } } return result; }
public long tell() throws IOException { return file.tell(); }
public Object __tojava__(Class cls) throws IOException { return file.__tojava__(cls); }
public void truncate(long position) throws IOException { file.truncate(position); }
public void close() throws IOException { file.close(); }
public void flush() throws IOException { file.flush(); }
public void seek(long pos, int how) throws IOException { file.seek(pos, how); }