Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.uber.hoodie.common.model.HoodieTestUtils.java

public static void writeRecordsToLogFiles(FileSystem fs, String basePath, Schema schema,
        List<HoodieRecord> updatedRecords) {
    Map<HoodieRecordLocation, List<HoodieRecord>> groupedUpdated = updatedRecords.stream()
            .collect(Collectors.groupingBy(HoodieRecord::getCurrentLocation));

    groupedUpdated.entrySet().forEach(s -> {
        HoodieRecordLocation location = s.getKey();
        String partitionPath = s.getValue().get(0).getPartitionPath();

        Writer logWriter;/*from w w w  . j  a  v  a 2  s .c o  m*/
        try {
            logWriter = HoodieLogFormat.newWriterBuilder().onParentPath(new Path(basePath, partitionPath))
                    .withFileExtension(HoodieLogFile.DELTA_EXTENSION).withFileId(location.getFileId())
                    .overBaseCommit(location.getCommitTime()).withFs(fs).build();

            Map<HoodieLogBlock.HeaderMetadataType, String> header = Maps.newHashMap();
            header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, location.getCommitTime());
            header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, schema.toString());
            logWriter.appendBlock(new HoodieAvroDataBlock(s.getValue().stream().map(r -> {
                try {
                    GenericRecord val = (GenericRecord) r.getData().getInsertValue(schema).get();
                    HoodieAvroUtils.addHoodieKeyToRecord(val, r.getRecordKey(), r.getPartitionPath(), "");
                    return (IndexedRecord) val;
                } catch (IOException e) {
                    return null;
                }
            }).collect(Collectors.toList()), header));
            logWriter.close();
        } catch (Exception e) {
            fail(e.toString());
        }
    });
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

/**
 * stringbyte./*from w  w  w. j  a  va  2s.  c om*/
 * 
 * @param fileData
 *            String .
 * @return byte,filedatenullnull.
 */
public static byte[] base64CodeDecode(String fileData) {
    if (fileData == null) {
        return null;
    }
    BASE64Decoder decoder = new BASE64Decoder();
    try {
        return decoder.decodeBuffer(fileData);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println(e.toString());
    }
    return null;
}

From source file:com.viettel.dms.download.DownloadFile.java

/**
 * Download file with urlConnection/*w ww  . j  a  va 2  s  .co  m*/
 * @author : BangHN
 * since : 1.0
 */
public static void downloadWithURLConnection(String url, File output, File tmpDir) {
    BufferedOutputStream os = null;
    BufferedInputStream is = null;
    File tmp = null;
    try {
        VTLog.i("Download ZIPFile", "Downloading url :" + url);

        tmp = File.createTempFile("download", ".tmp", tmpDir);
        URL urlDownload = new URL(url);
        URLConnection cn = urlDownload.openConnection();
        cn.addRequestProperty("session", HTTPClient.sessionID);
        cn.setConnectTimeout(CONNECT_TIMEOUT);
        cn.setReadTimeout(READ_TIMEOUT);
        cn.connect();
        is = new BufferedInputStream(cn.getInputStream());
        os = new BufferedOutputStream(new FileOutputStream(tmp));
        //cp nht dung lng tp tin request
        fileSize = cn.getContentLength();
        //vn c tr?ng hp khng c ContentLength
        if (fileSize < 0) {
            //mc nh = 4 MB
            fileSize = 4 * 1024 * 1024;
        }
        copyStream(is, os);
        tmp.renameTo(output);
        tmp = null;
    } catch (IOException e) {
        ServerLogger.sendLog("Download ZIPFile", e.getMessage() + "\n" + e.toString() + "\n" + url, false,
                TabletActionLogDTO.LOG_EXCEPTION);
        VTLog.e("UnexceptionLog", VNMTraceUnexceptionLog.getReportFromThrowable(e));
        throw new RuntimeException(e);
    } catch (Exception e) {
        VTLog.e("UnexceptionLog", VNMTraceUnexceptionLog.getReportFromThrowable(e));
        ServerLogger.sendLog("Download ZIPFile", e.getMessage() + "\n" + e.toString() + "\n" + url, false,
                TabletActionLogDTO.LOG_EXCEPTION);
        throw new RuntimeException(e);
    } finally {
        if (tmp != null) {
            try {
                tmp.delete();
                tmp = null;
            } catch (Exception ignore) {
                ;
            }
        }
        if (is != null) {
            try {
                is.close();
                is = null;
            } catch (Exception ignore) {
                ;
            }
        }
        if (os != null) {
            try {
                os.close();
                os = null;
            } catch (Exception ignore) {
                ;
            }
        }
    }
}

From source file:com.matze5800.paupdater.Functions.java

public static int getLocalVersion(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Process proc;//from  w w  w .  j a  v  a  2s . co  m
    BufferedReader reader;
    int localVer = 1;
    try {
        proc = Runtime.getRuntime().exec(new String[] { "/system/bin/getprop", "ro.goo.version" });
        reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        String result = reader.readLine();

        if (result.equals("") || result.equals(null)) {
            Log.i("Local Parser", "Not running on PA!!!");
            Log.i("Local Parser", "Disabling PA Prefs Restore");
            Toast.makeText(context, "You are not running PA! You should wipe data after flash!",
                    Toast.LENGTH_LONG).show();
            prefs.edit().putBoolean("prefPrefsRestore", false).commit();
            prefs.edit().putBoolean("NoPA", true).commit();
        } else {
            localVer = Integer.valueOf(result);
            prefs.edit().putBoolean("NoPA", false).commit();
        }
        Log.i("Local Parser", "Local version: " + localVer);
    } catch (IOException e) {
        Log.e("Local Parser", "Error parsing local version!");
        Log.e("Local Parser", e.toString());
    }
    return localVer;
}

From source file:com.alibaba.akita.io.HttpInvoker.java

/**
 * Vversion 2 remoteimageview download impl, use byte[] to decode.
 * Note: Recommanded to use this method instead of version 1.
 * NUM_RETRIES retry./*from  w  w w  .  ja v a2s .  c om*/
 * @param imgUrl
 * @param httpReferer http Referer
 * @return
 * @throws AkServerStatusException
 * @throws AkInvokeException
 */
public static Bitmap getBitmapFromUrl(String imgUrl, String httpReferer, ProgressBar progressBar)
        throws AkServerStatusException, AkInvokeException {
    imgUrl = imgUrl.trim();
    Log.v(TAG, "getBitmapFromUrl:" + imgUrl);

    int timesTried = 1;

    while (timesTried <= NUM_RETRIES) {
        timesTried++;
        try {
            if (progressBar != null) {
                progressBar.setProgress(0);
            }
            HttpGet request = new HttpGet(imgUrl);
            if (httpReferer != null)
                request.addHeader("Referer", httpReferer);
            HttpResponse response = client.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED
                    || statusCode == HttpStatus.SC_ACCEPTED) {
                HttpEntity resEntity = response.getEntity();
                InputStream inputStream = resEntity.getContent();

                byte[] imgBytes = retrieveImageData(inputStream, (int) (resEntity.getContentLength()),
                        progressBar);
                if (imgBytes == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }

                Bitmap bm = null;
                try {
                    bm = ImageUtil.decodeSampledBitmapFromByteArray(imgBytes, 0, imgBytes.length, 682, 682);
                } catch (OutOfMemoryError ooe) {
                    Log.e(TAG, ooe.toString(), ooe);
                    return null; // if oom, no need to retry.
                }
                if (bm == null) {
                    SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME);
                    continue;
                }
                return bm;
            } else {
                HttpEntity resEntity = response.getEntity();
                throw new AkServerStatusException(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(resEntity, CHARSET));
            }
        } catch (ClientProtocolException cpe) {
            Log.e(TAG, cpe.toString(), cpe);
            throw new AkInvokeException(AkInvokeException.CODE_HTTP_PROTOCOL_ERROR, cpe.toString(), cpe);
        } catch (IOException ioe) {
            Log.e(TAG, ioe.toString(), ioe);
            throw new AkInvokeException(AkInvokeException.CODE_CONNECTION_ERROR, ioe.toString(), ioe);
        } catch (IllegalStateException ise) {
            Log.e(TAG, ise.toString(), ise);
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, ise.toString(), ise);
        } catch (IllegalArgumentException iae) {
            throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, iae.toString(), iae);
        } catch (Exception e) {
            throw new AkInvokeException(AkInvokeException.CODE_UNKOWN_ERROR, e.toString(), e);
        }

    }

    return null;
}

From source file:com.iitb.cse.ConnectionInfo.java

public static void stoplistenForClients(Session session) {

    acceptConnection = false;/*  w  ww  .  ja v  a2  s .  c  o m*/
    Constants.currentSession = null;
    Constants.listenOnPort = false;

    if (Constants.dbManager != null) {
        Constants.dbManager.closeConnection();
    }
    Constants.dbManager = null;
    try {
        session.connectionSocket.close();
        session.connectionSocket = null;
        System.out.println("\nServer PORT Closed...Listening stopped!!!");
    } catch (IOException ex) {
        System.out.println("\nIOException : " + ex.toString() + "\n");
    } catch (Exception ex) {
        System.out.println("\nException" + ex.toString() + "\n");
    }
}

From source file:com.iitb.cse.ConnectionInfo.java

public static void writeToMyLog(int expid, String macAdrress, String message) {

    String location = "";

    if (!Constants.experimentDetailsDirectory.endsWith("/")) {
        location = Constants.experimentDetailsDirectory + "/";
    }/*from   w  ww.  jav  a 2s  .  co m*/

    location += Integer.toString(expid) + macAdrress + "_log.txt";
    File file = new File(location);
    try {
        FileWriter fw = new FileWriter(file, true);
        BufferedWriter bw = new BufferedWriter(fw);
        Date date = new Date();
        System.out.println(date);
        bw.write(date.toString() + " --> " + message + "\n");
        bw.close();
    } catch (IOException ex) {
        System.out.println("\nEXCEPTION [writeToMyLog]:" + ex.toString());
    }
}

From source file:com.redhat.rhn.common.hibernate.HibernateFactory.java

/**
 * utility to convert blob to byte array
 * @param fromBlob blob to convert/*from   w w w  . ja  va2 s  .c  om*/
 * @return byte array converted from blob
 */
public static byte[] blobToByteArray(Blob fromBlob) {

    if (fromBlob == null) {
        return new byte[0];
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {
        return toByteArrayImpl(fromBlob, baos);
    } catch (SQLException e) {
        LOG.error("SQL Error converting blob to byte array", e);
        throw new DatabaseException(e.toString());
    } catch (IOException e) {
        LOG.error("I/O Error converting blob to byte array", e);
        throw new DatabaseException(e.toString());
    } finally {
        try {
            baos.close();
        } catch (IOException ex) {
            throw new DatabaseException(ex.toString());
        }
    }
}

From source file:com.twitter.elephanttwin.util.HdfsUtils.java

/**
 * Read UTF-8 lines of text directly from HDFS.
 *//*from ww  w. j  a  v  a2  s  .  c  o m*/
public static Collection<String> readLines(FileSystem fs, Path path) throws IOException {
    Preconditions.checkNotNull(fs);
    Preconditions.checkNotNull(path);
    LOG.info("Reading from " + path.toUri());
    List<String> lines = Lists.newArrayList();
    try {
        if (!fs.exists(path)) {
            throw new IOException("File not found at " + path);
        }

        // TODO(Jimmy Lin): return CharStreams.readLines(new InputStreamReader(fs.open(path), "UTF-8"))
        // Note that this basically dups the functionality of HdfsFileTransfer.
        BufferedReader stream = new BufferedReader(new InputStreamReader(fs.open(path), "UTF-8"));
        String line;
        while ((line = stream.readLine()) != null) {
            lines.add(line);
        }
        LOG.info("Read " + lines.size() + " queries from " + path.toUri());
        return lines;
    } catch (IOException e) {
        LOG.warning("Failed to read " + path.toUri() + ": " + e.toString());
        throw e;
    }
}

From source file:it.uniud.ailab.dcore.launchers.Launcher.java

/**
 * Decide what Distillation (single or directory) execute and run it.
 *///  w ww . j  av  a 2s.  c o  m
private static void doWork() {

    switch (mode) {

    case EVALUATION:
        evaluate();
        break;
    case TRAINING_GENERATION:
        generateTrainingSet();
        break;
    default:
        try {
            if (inputPath.isFile()) {
                analyzeFile(inputPath);
            } else {
                analyzeDir(inputPath);
            }
        } catch (IOException ioe) {
            System.err.println(ioe.getLocalizedMessage());
            System.err.println(ioe.toString());
        }
    }

}