List of usage examples for java.io EOFException toString
public String toString()
From source file:com.frostwire.search.youtube.jd.Request.java
public static byte[] read(final HTTPConnectionImpl con) throws IOException { final InputStream is = con.getInputStream(); byte[] ret = null; if (is == null) { // TODO: check if we have t close con here return null; }/*from www.ja va2 s . c om*/ ReusableByteArrayOutputStream tmpOut; ReusableByteArrayOutputStream tmpOut2 = ReusableByteArrayOutputStreamPool .getReusableByteArrayOutputStream(1048); final long contentLength = con.getLongContentLength(); if (contentLength != -1) { final int length = contentLength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) contentLength; tmpOut = ReusableByteArrayOutputStreamPool.getReusableByteArrayOutputStream(length); } else { tmpOut = ReusableByteArrayOutputStreamPool.getReusableByteArrayOutputStream(16384); } boolean okay = false; /* added "Corrupt GZIP trailer" for CamWinsCom */ try { int len; while ((len = is.read(tmpOut2.getInternalBuffer())) != -1) { if (len > 0) { tmpOut.write(tmpOut2.getInternalBuffer(), 0, len); } } okay = true; } catch (final EOFException e) { e.printStackTrace(); okay = true; } catch (final IOException e) { if (e.toString().contains("end of ZLIB") || e.toString().contains("Premature") || e.toString().contains("Corrupt GZIP trailer")) { //System.out.println("Try workaround for " + e); okay = true; } else { throw e; } } finally { try { is.close(); } catch (final Exception e) { } try { /* disconnect connection */ con.disconnect(); } catch (final Exception e) { } ReusableByteArrayOutputStreamPool.reuseReusableByteArrayOutputStream(tmpOut2); if (okay) { ret = tmpOut.toByteArray(); } ReusableByteArrayOutputStreamPool.reuseReusableByteArrayOutputStream(tmpOut); tmpOut = null; tmpOut2 = null; } return ret; }
From source file:com.sun.mail.pop3.POP3Folder.java
/** * Return the unique ID string for this message, or null if * not available. Uses the POP3 UIDL command. * * @return unique ID string//from ww w . j a va 2 s .c o m * @exception MessagingException */ public synchronized String getUID(Message msg) throws MessagingException { checkOpen(); POP3Message m = (POP3Message) msg; try { if (m.uid == POP3Message.UNKNOWN) m.uid = port.uidl(m.getMessageNumber()); return m.uid; } catch (EOFException eex) { close(false); throw new FolderClosedException(this, eex.toString()); } catch (IOException ex) { throw new MessagingException("error getting UIDL", ex); } }
From source file:com.sun.mail.pop3.POP3Folder.java
/** * Prefetch information about POP3 messages. * If the FetchProfile contains <code>UIDFolder.FetchProfileItem.UID</code>, * POP3 UIDs for all messages in the folder are fetched using the POP3 * UIDL command.//from w w w . j a va2 s. co m * If the FetchProfile contains <code>FetchProfile.Item.ENVELOPE</code>, * the headers and size of all messages are fetched using the POP3 TOP * and LIST commands. */ public synchronized void fetch(Message[] msgs, FetchProfile fp) throws MessagingException { checkReadable(); if (!doneUidl && fp.contains(UIDFolder.FetchProfileItem.UID)) { /* * Since the POP3 protocol only lets us fetch the UID * for a single message or for all messages, we go ahead * and fetch UIDs for all messages here, ignoring the msgs * parameter. We could be more intelligent and base this * decision on the number of messages fetched, or the * percentage of the total number of messages fetched. */ String[] uids = new String[message_cache.size()]; try { if (!port.uidl(uids)) return; } catch (EOFException eex) { close(false); throw new FolderClosedException(this, eex.toString()); } catch (IOException ex) { throw new MessagingException("error getting UIDL", ex); } for (int i = 0; i < uids.length; i++) { if (uids[i] == null) continue; POP3Message m = (POP3Message) getMessage(i + 1); m.uid = uids[i]; } doneUidl = true; // only do this once } if (fp.contains(FetchProfile.Item.ENVELOPE)) { for (int i = 0; i < msgs.length; i++) { try { POP3Message msg = (POP3Message) msgs[i]; // fetch headers msg.getHeader(""); // fetch message size msg.getSize(); } catch (MessageRemovedException mex) { // should never happen, but ignore it if it does } } } }
From source file:com.docd.purefm.tasks.SearchCommandLineTask.java
@Override protected Void doInBackground(String... params) { final CommandFind command = new CommandFind(mStartDirectory.getAbsolutePath(), params); // NOTE this doesn't use Shell because we can't create a new CommandLineFile from // CommandOutput because executing readlink (which is done in CommandLineFile constructor) // will freeze the whole Shell DataOutputStream os = null;//www . j a va 2 s . c o m BufferedReader is = null; BufferedReader err = null; Process process = null; try { process = Runtime.getRuntime().exec(mSettings.isSuEnabled() ? "su" : "sh"); os = new DataOutputStream(process.getOutputStream()); is = new BufferedReader(new InputStreamReader(process.getInputStream())); err = new BufferedReader(new InputStreamReader(process.getErrorStream())); os.writeBytes(command.toString()); os.writeBytes("exit\n"); os.flush(); String line; try { while (!isCancelled() && (line = is.readLine()) != null) { this.publishProgress(CommandLineFile.fromLSL(null, line)); } } catch (EOFException e) { //ignore } try { while (!isCancelled() && (line = err.readLine()) != null) { final Matcher denied = DENIED.matcher(line); if (denied.matches()) { this.mDenied.add(denied.group(1)); } } } catch (EOFException e) { //ignore } process.waitFor(); } catch (Exception e) { Log.w("Exception while searching", e.toString()); } finally { IOUtils.closeQuietly(os); IOUtils.closeQuietly(is); IOUtils.closeQuietly(err); if (process != null) { try { process.destroy(); } catch (Exception e) { //ignored } } } return null; }
From source file:net.lightbody.bmp.proxy.jetty.http.HttpRequest.java
private void extractParameters() { if (_paramsExtracted) return;//from w w w . ja v a 2 s . c o m _paramsExtracted = true; if (_parameters == null) _parameters = new MultiMap(16); // Handle query string String encoding = getCharacterEncoding(); if (encoding == null) { _uri.putParametersTo(_parameters); } else { // An encoding has been set, so reencode query string. String query = _uri.getQuery(); if (query != null) UrlEncoded.decodeTo(query, _parameters, encoding); } // handle any content. if (_state == __MSG_RECEIVED) { String content_type = getField(HttpFields.__ContentType); if (content_type != null && content_type.length() > 0) { content_type = StringUtil.asciiToLowerCase(content_type); content_type = HttpFields.valueParameters(content_type, null); if (HttpFields.__WwwFormUrlEncode.equalsIgnoreCase(content_type) && HttpRequest.__POST.equals(getMethod())) { int content_length = getIntField(HttpFields.__ContentLength); if (content_length == 0) log.debug("No form content"); else { try { int max = content_length; if (__maxFormContentSize > 0) { if (max < 0) max = __maxFormContentSize; else if (max > __maxFormContentSize) throw new IllegalStateException("Form too large"); } // Read the content ByteArrayOutputStream2 bout = new ByteArrayOutputStream2(max > 0 ? max : 4096); InputStream in = getInputStream(); // Copy to a byte array. // TODO - this is very inefficient and we could // save lots of memory by streaming this!!!! IO.copy(in, bout, max); if (bout.size() == __maxFormContentSize && in.available() > 0) throw new IllegalStateException("Form too large"); // Add form params to query params UrlEncoded.decodeTo(bout.getBuf(), 0, bout.getCount(), _parameters, encoding); } catch (EOFException e) { LogSupport.ignore(log, e); } catch (IOException e) { if (log.isDebugEnabled()) log.warn(LogSupport.EXCEPTION, e); else log.warn(e.toString()); } } } } } }