Examples of ReadFileResult


Examples of org.jnode.net.nfs.nfs2.ReadFileResult

            while (true) {
                length = Math.min(NFS2Client.MAX_DATA, dest.remaining());
                if (length == 0) {
                    return;
                }
                ReadFileResult result =
                        client.readFile(entry.getFileHandle(), (int) fileOffset, length);
                byte[] data = result.getData();
                length = data.length;
                fileOffset += length;
                dest.put(data);
            }
        } catch (NFS2Exception e) {
View Full Code Here

Examples of org.jnode.net.nfs.nfs2.ReadFileResult

    private int fillBuffer() throws IOException {
        if (fileOffset >= fileAttribute.getSize()) {
            return 0;
        }
        ReadFileResult readFileResult;
        try {
            readFileResult = nfsClient.readFile(fileHandle, (int) fileOffset, DEFAULT_BUFFER_SIZE);
        } catch (NFS2Exception e) {
            throw new IOException(e.getMessage());
        }
        fileAttribute = readFileResult.getFileAttribute();
        fileOffset += readFileResult.getData().length;
        System.arraycopy(readFileResult.getData(), 0, buffer, 0, readFileResult.getData().length);
        bufferPosition = 0;
        bufferCount = readFileResult.getData().length;
        return bufferCount;
    }
View Full Code Here

Examples of org.mmisw.orrclient.gwt.client.rpc.ReadFileResult

   * @param file The file to read
   * @return the result of the operation.
   * @throws Exception
   */
  private static ReadFileResult readFileWithConversionToUtf8(File file) throws Exception {
    ReadFileResult result = new ReadFileResult();
   
    try {
      String str = IOUtils.toString(new FileInputStream(file), "UTF-8");
      result.setLogInfo("OK: file can be read as UTF-8 (no conversion necessary)");
      result.setError("setting error to avoid unnecesary conversion");
      result.setContents(str);
      return result;

    }
    catch(Throwable ex) {
      result.setLogInfo("OK: file cannot be read as UTF-8 directly.");
    }
   
    byte[] bytes = IOUtils.toByteArray(new FileInputStream(file));
   
    Collection<String> charsets = Utf8Util.isUtf8(bytes);
   
    if ( charsets == null ) {
      // charsets == null means the bytes are good UTF-8, so this
      // should NOT happen.
      result.addLogInfo("OK: already in UTF-8.");
      result.setError("setting error to avoid unnecesary conversion");
      result.setContents(new String(bytes, "UTF-8"));
      return result;
    }
   
    result.addLogInfo("Charset of the file may be one of: " +charsets+ "\n");
    result.addLogInfo("Attempting conversiones..\n");
   
    for ( String charsetName : charsets ) {
      try {
        String outputStr = _asString(bytes, charsetName);
        result.addLogInfo("Conversion from " +charsetName+ ": OK.\n");
        result.setContents(outputStr);
        return result;
      }
      catch(CharacterCodingException ex) {
        // continue with the other possible charsets...
      }
    }
   
    result.setError("None of the conversions from the possible detected charsets "
        + " was successful: " +charsets
    );
    result.setContents(null);
    return result;
  }
View Full Code Here

Examples of org.mmisw.orrclient.gwt.client.rpc.ReadFileResult

    File file = new File(filename);
   
    File outFile = new File(file.getParent(), "utf8-" +file.getName());
    String outFilename = outFile.getPath();
   
    ReadFileResult result = readFileWithConversionToUtf8(file);
    System.out.println("readFileWithConversionToUtf8:");
    String error = result.getError();
    if ( error != null ) {
      System.out.println("error: " +result.getError());
    }
    System.out.println("logInfo:\n\t" +result.getLogInfo().replaceAll("\n", "\n\t"));
   
    if ( error == null ) {
      _writeStringTo(result.getContents(), outFilename);
      System.out.println("Output written to " +outFilename)
     
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.