Ejemplo n.º 1
0
 final void file_truncate() {
   try {
     file.truncate(file.tell());
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 2
0
 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;
      }
Ejemplo n.º 6
0
  /** 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;
  }
Ejemplo n.º 7
0
 final void file_truncate(long position) {
   try {
     file.truncate(position);
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 8
0
 final void file_flush() {
   if (closed) err_closed();
   try {
     file.flush();
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 9
0
 final void file_seek(long pos, int how) {
   if (closed) err_closed();
   try {
     file.seek(pos, how);
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 10
0
 final long file_tell() {
   if (closed) err_closed();
   try {
     return file.tell();
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 11
0
 final void file_write(String s) {
   if (closed) err_closed();
   try {
     file.write(s);
     softspace = false;
   } catch (IOException e) {
     throw Py.IOError(e);
   }
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 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);
   }
 }
Ejemplo n.º 14
0
 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;
   }
 }
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 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();
 }
Ejemplo n.º 17
0
 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();
 }
Ejemplo n.º 18
0
 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;
      }
Ejemplo n.º 20
0
 public long tell() throws IOException {
   return file.tell();
 }
Ejemplo n.º 21
0
 public Object __tojava__(Class cls) throws IOException {
   return file.__tojava__(cls);
 }
Ejemplo n.º 22
0
 public void truncate(long position) throws IOException {
   file.truncate(position);
 }
Ejemplo n.º 23
0
 public void close() throws IOException {
   file.close();
 }
Ejemplo n.º 24
0
 public void flush() throws IOException {
   file.flush();
 }
Ejemplo n.º 25
0
 public void seek(long pos, int how) throws IOException {
   file.seek(pos, how);
 }