Open - Receive to this server and send the response.
@exception Exception File exception.
557872
public void open(String strKeyArea, int iOpenMode, boolean bDirection, String strFields, Object objInitialKey, Object objEndKey, byte[] byBehaviorData) throws DBException, RemoteException
    {
        BaseTransport  transport = this.createProxyTransport(OPEN);
        transport.addParam(KEY, strKeyArea);
        transport.addParam(OPEN_MODE, iOpenMode);
        transport.addParam(DIRECTION, bDirection);
        transport.addParam(FIELDS, strFields);
        transport.addParam(INITIAL_KEY, objInitialKey);
        transport.addParam(END_KEY, objEndKey);
        transport.addParam(BEHAVIOR_DATA, byBehaviorData);
        Object strReturn = transport.sendMessageAndGetReply();
        Object objReturn = transport.convertReturnObject(strReturn);
        this.checkDBException(objReturn);
    }
300500
@Override
	public void open(Configuration parameters) throws Exception {
		try {
			synchronized (lock) {
				createConnection();
			}
		}
		catch (IOException e) {
			throw new IOException("Cannot connect to socket server at " + hostName + ":" + port, e);
		}
	}
84024
@Override
    public void open() throws Exception {
        lasReader = ALasReader.getReader(lasFile, crs);
        lasReader.open();
        lasHeader = lasReader.getHeader();
        isOpen = true;
    }
139882
private void processRequest(HttpServletRequest request, HttpServletResponse response, boolean content)
            throws IOException {
        // Validate the requested file ------------------------------------------------------------

        // Get requested file by path info.
        String requestedFile = request.getPathInfo();
        if (logger.isDebugEnabled()) {
            logger.debug("Requested path:" + requestedFile);
        }

        // Check if file is actually supplied to the request URL.
        if (requestedFile == null) {
            logger.debug("No file requested, return 404.");
            // Do your thing if the file is not supplied to the request URL.
            // Throw an exception, or send 404, or show default/warning page, or just ignore it.
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        Configuration rootConfiguration = (Configuration) request.getServletContext().getAttribute(Configuration.class.getName());
        Configuration runtimeConfiguration = rootConfiguration.subset("runtime-settings");

        String basePath = runtimeConfiguration.getString("cache-path");
        int bufferSize = runtimeConfiguration.getInteger("cache-buffer-size", DEFAULT_BUFFER_SIZE);
        long expireTime = runtimeConfiguration.getLong("cache-expire-time", DEFAULT_EXPIRE_TIME);

        // URL-decode the file name (might contain spaces and on) and prepare file object.
        String fDecodedPath = URLDecoder.decode(requestedFile, "UTF-8");
        File file = new File(basePath, fDecodedPath);

        // Check if file actually exists in filesystem.
        if (!file.exists()) {
            logger.debug("Requested file not found, return 404.");
            // Do your thing if the file appears to be non-existing.
            // Throw an exception, or send 404, or show default/warning page, or just ignore it.
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        // Prepare some variables. The ETag is an unique identifier of the file.
        String fileName = file.getName();
        long length = file.length();
        long lastModified = file.lastModified();
        String eTag = fileName + "_" + length + "_" + lastModified;
        long expires = System.currentTimeMillis() + expireTime;

        // Validate request headers for caching ---------------------------------------------------
        // If-None-Match header should contain "*" or ETag. If so, then return 304.
        String ifNoneMatch = request.getHeader("If-None-Match");
        if (ifNoneMatch != null && matches(ifNoneMatch, eTag)) {
            logger.debug("IfNoneMatch/Etag not matching, return 304.");
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", eTag); // Required in 304.
            response.setDateHeader("Expires", expires); // Postpone cache with 1 week.
            return;
        }

        // If-Modified-Since header should be greater than LastModified. If so, then return 304.
        // This header is ignored if any If-None-Match header is specified.
        long ifModifiedSince = request.getDateHeader("If-Modified-Since");
        if (ifNoneMatch == null && ifModifiedSince != -1 && ifModifiedSince + 1000 > lastModified) {
            logger.debug("IfModifiedSince not matching, return 304.");
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", eTag); // Required in 304.
            response.setDateHeader("Expires", expires); // Postpone cache with 1 week.
            return;
        }

        // Validate request headers for resume ----------------------------------------------------
        // If-Match header should contain "*" or ETag. If not, then return 412.
        String ifMatch = request.getHeader("If-Match");
        if (ifMatch != null && !matches(ifMatch, eTag)) {
            logger.debug("ifMatch not matching, return 412.");
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }

        // If-Unmodified-Since header should be greater than LastModified. If not, then return 412.
        long ifUnmodifiedSince = request.getDateHeader("If-Unmodified-Since");
        if (ifUnmodifiedSince != -1 && ifUnmodifiedSince + 1000 <= lastModified) {
            logger.debug("ifUnmodifiedSince not matching, return 412.");
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }

        // Prepare and initialize response --------------------------------------------------------
        // Get content type by file name and content disposition.
        String contentType = getServletContext().getMimeType(fileName);
        String disposition = "inline";

        // If content type is unknown, then set the default value.
        // For all content types, see: http://www.w3schools.com/media/media_mimeref.asp
        // To add new content types, add new mime-mapping entry in web.xml.
        if (contentType == null) {
            contentType = "application/octet-stream";
        }

        // If content type is text, expand content type with the one and right character encoding.
        if (contentType.startsWith("text")) {
            contentType += ";charset=UTF-8";
        } // Else, expect for images, determine content disposition. If content type is supported by
        // the browser, then set to inline, else attachment which will pop a 'save as' dialogue.
        else if (!contentType.startsWith("image")) {
            String accept = request.getHeader("Accept");
            disposition = accept != null && accepts(accept, contentType) ? "inline" : "attachment";
        }

        // Initialize response.
        response.reset();
        response.setBufferSize(bufferSize);
        response.setHeader("Content-Disposition", disposition + ";filename=\"" + fileName + "\"");
        response.setHeader("Accept-Ranges", "bytes");
        response.setHeader("ETag", eTag);
        response.setDateHeader("Last-Modified", lastModified);
        response.setDateHeader("Expires", expires);

        // Send requested file (part(s)) to client ------------------------------------------------
        // Prepare streams.
        FileInputStream input = null;
        OutputStream output = null;

        if (content) {
            logger.debug("Content requested,streaming.");
            // Open streams.
            input = new FileInputStream(file);
            output = response.getOutputStream();
            long streamed = stream(input, output, bufferSize);
            if (logger.isDebugEnabled()) {
                logger.debug("Bytes streamed:" + streamed);
            }
        }

    }
1257038
public static void main(String[] args) throws Exception {
		String dowloadFolder = "images/";
		String urlsFile = "urls.txt";
		int numUrls = 1000;
		int urlsToSkip = 0;
		downloadFromUrlsFile(dowloadFolder, urlsFile, numUrls, urlsToSkip);
	}
271962
public void start()
    throws Exception
  {
    if (_port < 0 && _unixPath == null) {
      return;
    }

    if (! _lifecycle.toStarting())
      return;

    boolean isValid = false;
    try {
      bind();
      postBind();

      enable();

      _acceptTask = new AcceptTcp(this, _serverSocket);
      _threadPool.execute(_acceptTask);

      // _connThreadPool.start();

      _suspendAlarm = new Alarm(new SuspendReaper());
      _suspendAlarm.runAfter(_suspendReaperTimeout);

      isValid = true;
    } finally {
      if (! isValid) {
        close();
      }
    }
  }
898921
@Override
    public Response execute(Request request) throws IOException {
        HttpURLConnection connection = openConnection(request);
        sendRequest(connection, request);
        return readResponse(connection);
    }
1054455
protected function sendRequest()
    {
        try {
            $this->response = $this->client->send($this->request);
        } catch (RequestException $e) {
            $this->response = $e->getResponse();

            if (null === $this->response) {
                if ($this->throwsRequestException) {
                    throw $e;
                }
            }

            if ($this->throwsRequestException) {
                throw new \Exception((string)$this->response->getBody());
            }
        }
    }
860069
void sendError(HttpResponseStatus status, Throwable ex) {
    String msg;

    if (ex instanceof InvocationTargetException) {
      msg = String.format("Exception Encountered while processing request : %s", ex.getCause().getMessage());
    } else {
      msg = String.format("Exception Encountered while processing request: %s", ex.getMessage());
    }

    // Send the status and message, followed by closing of the connection.
    responder.sendString(status, msg, new DefaultHttpHeaders().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE));
    if (bodyConsumer != null) {
      bodyConsumerError(ex);
    }
  }
30717
public void init() throws Exception {

        // If the status file exists, make sure it doesn't indicate
        // that the server is running!
        if (_statusFile.exists()) {
            ServerStatusMessage[] messages = getAllMessages();
            ServerStatusMessage lastMessage = messages[messages.length - 1];
            if (lastMessage.getState() == ServerState.STARTED) {
                throw new Exception("The server is already running or was shut down unexpectedly.\n"
                        + "If the server has shut down unexpectedly, you must manually delete\n"
                        + "the following file: "
                        + _statusFile.getPath()
                        + "\n"
                        + "then try again.");
            }
        }

        _statusFile.clear();
        _statusFile.append(ServerState.NOT_STARTING,
                           "Waiting for startup to begin");
    }
1323164
@PreAuthorize("isAuthenticated()")
    public E uploadFile(MultipartFile file) throws Exception {

        if (file == null) {
            final String errMsg = "Upload failed. File is null.";
            LOG.error(errMsg);
            throw new Exception(errMsg);
        } else if (file.isEmpty()) {
            final String errMsg = "Upload failed. File is empty.";
            LOG.error(errMsg);
            throw new Exception(errMsg);
        }

        InputStream is = null;
        byte[] fileByteArray = null;
        E fileToPersist = getEntityClass().newInstance();

        try {
            is = file.getInputStream();
            fileByteArray = IOUtils.toByteArray(is);
        } catch (Exception e) {
            throw new Exception("Could not create the bytearray: " + e.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }

        fileToPersist.setFile(fileByteArray);
        fileToPersist.setFileType(file.getContentType());
        fileToPersist.setFileName(file.getOriginalFilename());

        dao.saveOrUpdate(fileToPersist);

        return fileToPersist;
    }
315567
public void sendRequest()
        throws IOException
    {
        if (_conn instanceof HttpURLConnection) {
            HttpURLConnection httpConn = (HttpURLConnection) _conn;

            _statusCode = 500;

            try {
                _statusCode = httpConn.getResponseCode();
            } catch (Exception e) {
            }

            parseResponseHeaders(httpConn);

            InputStream is = null;

            if (_statusCode != 200) {
                StringBuffer sb = new StringBuffer();
                int ch;

                try {
                    is = httpConn.getInputStream();

                    if (is != null) {
                        while ((ch = is.read()) >= 0)
                            sb.append((char) ch);

                        is.close();
                    }

                    is = httpConn.getErrorStream();
                    if (is != null) {
                        while ((ch = is.read()) >= 0)
                            sb.append((char) ch);
                    }

                    _statusMessage = sb.toString();
                } catch (FileNotFoundException e) {
                    throw new HessianConnectionException("HessianProxy cannot connect to '" + _url, e);
                } catch (IOException e) {
                    if (is == null)
                        throw new HessianConnectionException(_statusCode + ": " + e, e);
                    else
                        throw new HessianConnectionException(_statusCode + ": " + sb, e);
                }

                if (is != null)
                    is.close();

                throw new HessianConnectionException(_statusCode + ": " + sb.toString());
            }
        }
    }
521490
public void sendData(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
//        res.setContentType("application/x-java-jnlp-file");
//x        PrintWriter out = new PrintWriter(res.getOutputStream());
//        PrintWriter out = res.getWriter();

//        this.printXML(req, out);
//        out.flush();
        
        ClassService classService = ClassServiceUtility.getClassService();
        if (classService == null)
            return;    // Never
        ClassFinder classFinder = classService.getClassFinder(null);
        if (classFinder == null)
            return;
        HttpServiceTracker tracker = (HttpServiceTracker)classFinder.getClassBundleService(null, WEB_START_ACTIVATOR_CLASS, null, null, -1);
        if (tracker == null)
            return;
        Servlet servlet = tracker.getServlet();
        if (servlet == null)
            return;
        servlet.service((HttpServletRequest)req, (HttpServletResponse)res);
    }
1234791
private InputStream safeOpen(String file) {
    URL url = bundle.getEntry(file);
    if (url != null) {
      try {
        return url.openStream();
      } catch (IOException e) {
        // if we get an IOException just return null for default page.
      }
    }
    return null;
  }
234804
private void openStream() throws IOException {
    if (mClosed) {
      throw new IOException("Stream closed");
    }
    if (mMultiRangeChunkSize <= 0) {
      throw new IOException(ExceptionMessage.BLOCK_SIZE_INVALID.getMessage(mMultiRangeChunkSize));
    }

    if (mStream != null) { // stream is already open
      return;
    }
    final long endPos = mPos + mMultiRangeChunkSize - (mPos % mMultiRangeChunkSize);
    mEndPos = endPos;
    mStream = createStream(mPos, endPos);
  }
867941
public void openSession(String fileName) throws SQLException, SAXException, IOException, Exception {
		getSession().open(fileName);
	}
175544
private static int port(final File file) throws Exception {
        while (!file.exists()) {
            TimeUnit.MILLISECONDS.sleep(1L);
        }
        final int port;
        try (InputStream input = Files.newInputStream(file.toPath())) {
            // @checkstyle MagicNumber (1 line)
            final byte[] buf = new byte[10];
            while (true) {
                if (input.read(buf) > 0) {
                    break;
                }
            }
            port = Integer.parseInt(
                new TrimmedText(new Utf8String(buf)).asString()
            );
        }
        return port;
    }