semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public WebHttpResponse execute(HttpRequest request) throws Exception {
        WebHttpResponse response = new WebHttpResponse(request);
        if (iSSLClassesAvailable == -1) {
            try {
                Class.forName("javax.net.ssl.SSLSocket");
                iSSLClassesAvailable = 1;
            } catch (ClassNotFoundException cnf) {
                iSSLClassesAvailable = 0;
            }
        }
        try {
            request.getClass().getMethod("getThinkTime", null);
            long thinkTime = request.getThinkTime();
            if (thinkTime > 0) Thread.sleep(thinkTime);
        } catch (Exception e) {
        }
        if (httpRequestHandler == null) {
            httpRequestHandler = new WebHttpRequestHandler();
        }
        currentPageNumber = request.getPageNumber();
        currentPageOrder = request.getPageOrder();
        long start = System.currentTimeMillis();
        if ((currentPageOrder == HttpRequest.PAGE_START) || (currentPageOrder == HttpRequest.PAGE_ONLY)) {
            pageStart = start;
            currentPageName = request.getURL();
        }
        if (iSSLClassesAvailable == 1 && request.getSecure() == true) {
            SSLHttpExecutor ssl = null;
            if (sslExecutor == null) sslExecutor = new WebSSLHttpExecutor(httpRequestHandler);
            ssl = (SSLHttpExecutor) sslExecutor;
            ssl.execute(request, response);
            setResponseEndingData(request, response, start);
            return response;
        } else if (iSSLClassesAvailable == 0 && request.getSecure() == true) {
            System.out.println(HttpResourceBundle.SSL_NOTSUPPORTED);
        }
        String strHost = request.getHost();
        int port = request.getPort();
        if (port != iLastPort || strLastHost == null || strHost.regionMatches(0, strLastHost, 0, strLastHost.length()) != true) {
            if ((connectToServer(response, strHost, port)) == false) {
                response.setCode(-1);
                return response;
            }
        }
        if (httpRequestHandler.sendRequest(request, to_server) == false) {
            if (connectToServer(response, strHost, port) == false) {
                response.setCode(-1);
                return response;
            } else {
                if (httpRequestHandler.sendRequest(request, to_server) == false) {
                    response.setCode(-1);
                    return response;
                }
            }
        }
        httpRequestHandler.getServerResponse(request, response, from_server, socketBufSize);
        if (response.getCode() == 0) {
            if (connectToServer(response, strHost, port) == true) {
                if (httpRequestHandler.sendRequest(request, to_server) == true) {
                    httpRequestHandler.getServerResponse(request, response, from_server, socketBufSize);
                }
            }
        }
        if (response.getShouldCloseSocket() == true) strLastHost = null;
        setResponseEndingData(request, response, start);
        return response;
    }
public static void main(String[] args) {
        File directory = new File(args[0]);
        File[] files = directory.listFiles();
        try {
            PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
            for (int i = 0; i < files.length; i++) {
                BufferedReader reader = new BufferedReader(new FileReader(files[i]));
                while (reader.ready()) writer.println(reader.readLine());
                reader.close();
            }
            writer.flush();
            writer.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void copy(File srouceFile, File destinationFile) throws IOException {
        FileChannel sourceChannel = new FileInputStream(srouceFile).getChannel();
        FileChannel destinationChannel = new FileOutputStream(destinationFile).getChannel();
        destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        destinationChannel.close();
    }
protected URLConnection openConnection(URL url) throws IOException {
            URLConnection con = url.openConnection();
            if ("HTTPS".equalsIgnoreCase(url.getProtocol())) {
                HttpsURLConnection scon = (HttpsURLConnection) con;
                try {
                    scon.setSSLSocketFactory(SSLUtil.getSSLSocketFactory(ks, password, alias));
                    scon.setHostnameVerifier(SSLUtil.getHostnameVerifier(SSLUtil.HOSTCERT_MIN_CHECK));
                } catch (GeneralException e) {
                    throw new IOException(e.getMessage());
                } catch (GeneralSecurityException e) {
                    throw new IOException(e.getMessage());
                }
            }
            return con;
        }
private void prepareDigestFromTextArea() throws NoSuchAlgorithmException, UnsupportedEncodingException {
        log.println("\nCalculating digest ...\n");
        java.security.MessageDigest md5 = java.security.MessageDigest.getInstance("MD5");
        md5.update(dataArea.getText().getBytes("UTF8"));
        byte[] digest = md5.digest();
        log.println("digest:\n" + formatAsHexString(digest));
        log.println("Done.");
        setEncodedDigest(encodeFromBytes(digest));
    }
public RandomAccessFileOrArray(URL url) throws IOException {
        InputStream is = url.openStream();
        try {
            this.arrayIn = InputStreamToArray(is);
        } finally {
            try {
                is.close();
            } catch (IOException ioe) {
            }
        }
    }
public void uploadFile(ActionEvent event) throws IOException {
        InputFile inputFile = (InputFile) event.getSource();
        synchronized (inputFile) {
            ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
            String fileNewPath = arrangeUplodedFilePath(context.getRealPath(""), inputFile.getFile().getName());
            File file = new File(fileNewPath);
            System.out.println(fileNewPath);
            DataInputStream inStream = new DataInputStream(new FileInputStream(inputFile.getFile()));
            DataOutputStream outStream = new DataOutputStream(new FileOutputStream(file));
            int i = 0;
            byte[] buffer = new byte[512];
            while ((i = inStream.read(buffer, 0, 512)) != -1) outStream.write(buffer, 0, i);
        }
    }
public static String MD5(String text) throws ProducteevSignatureException {
        try {
            MessageDigest md;
            md = MessageDigest.getInstance(ALGORITHM);
            byte[] md5hash;
            md.update(text.getBytes("utf-8"), 0, text.length());
            md5hash = md.digest();
            return convertToHex(md5hash);
        } catch (NoSuchAlgorithmException nsae) {
            throw new ProducteevSignatureException("No such algorithm : " + ALGORITHM, nsae);
        } catch (UnsupportedEncodingException e) {
            throw new ProducteevSignatureException("No such algorithm : " + ALGORITHM, e);
        }
    }
public static void copyFile(File from, File to) throws IOException {
        if (from.isDirectory()) {
            if (!to.exists()) {
                to.mkdir();
            }
            File[] children = from.listFiles();
            for (int i = 0; i < children.length; i++) {
                if (children[i].getName().equals(".") || children[i].getName().equals("..")) {
                    continue;
                }
                if (children[i].isDirectory()) {
                    File f = new File(to, children[i].getName());
                    copyFile(children[i], f);
                } else {
                    copyFile(children[i], to);
                }
            }
        } else if (from.isFile() && (to.isDirectory() || to.isFile())) {
            if (to.isDirectory()) {
                to = new File(to, from.getName());
            }
            FileInputStream in = new FileInputStream(from);
            FileOutputStream out = new FileOutputStream(to);
            byte[] buf = new byte[32678];
            int read;
            while ((read = in.read(buf)) > -1) {
                out.write(buf, 0, read);
            }
            closeStream(in);
            closeStream(out);
        }
    }
void openTextFile(String urlString, boolean install) {
        StringBuffer sb = null;
        try {
            URL url = new URL(urlString);
            InputStream in = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) sb.append(line + "\n");
            in.close();
        } catch (IOException e) {
            if (!(install && urlString.endsWith("StartupMacros.txt"))) IJ.error("URL Opener", "" + e);
            sb = null;
        }
        if (sb != null) {
            if (install) (new MacroInstaller()).install(new String(sb)); else {
                int index = urlString.lastIndexOf("/");
                if (index != -1 && index <= urlString.length() - 1) urlString = urlString.substring(index + 1);
                (new Editor()).create(urlString, new String(sb));
            }
        }
    }
public void validateXml(InputStream inputData, ErrorHandler errorHandler) throws SAXException, IOException, Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(false);
        spf.setNamespaceAware(true);
        try {
            SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            URL schemaURL = new URL(schemeUrl);
            InputStream urlStream = null;
            try {
                urlStream = schemaURL.openStream();
            } catch (IOException ex) {
                if (defaultUrl != null) {
                    schemaURL = new URL(defaultUrl);
                    urlStream = schemaURL.openStream();
                } else {
                    throw ex;
                }
            }
            LOGGER.debug("Uses schema url : " + schemaURL);
            StreamSource sss = new StreamSource(urlStream);
            Schema schema = schemaFactory.newSchema(sss);
            spf.setSchema(schema);
            SAXParser parser = spf.newSAXParser();
            XMLReader reader = parser.getXMLReader();
            reader.setErrorHandler(errorHandler);
            reader.parse(new InputSource(inputData));
        } catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) destFile.createNewFile();
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) source.close();
            if (destination != null) destination.close();
        }
    }
private void writeToDisk(byte[] download) throws IOException {
        File target = new File(TARGET_FILENAME);
        InputStream downloadedFromNetwork = new ByteArrayInputStream(download);
        FileOutputStream fileOnDisk = null;
        try {
            try {
                fileOnDisk = new FileOutputStream(target);
                fileOnDisk.write("test".getBytes());
            } catch (Exception e) {
                target = new File(PMS.getConfiguration().getTempFolder(), TARGET_FILENAME);
            } finally {
                fileOnDisk.close();
            }
            fileOnDisk = new FileOutputStream(target);
            int bytesSaved = IOUtils.copy(downloadedFromNetwork, fileOnDisk);
            logger.info("Wrote " + bytesSaved + " bytes to " + target.getAbsolutePath());
        } finally {
            IOUtils.closeQuietly(downloadedFromNetwork);
            IOUtils.closeQuietly(fileOnDisk);
        }
    }
public void copyToZip(ZipOutputStream zout, String entryName) throws IOException {
        close();
        ZipEntry entry = new ZipEntry(entryName);
        zout.putNextEntry(entry);
        if (!isEmpty() && this.tmpFile.exists()) {
            InputStream in = new FileInputStream(this.tmpFile);
            IOUtils.copyTo(in, zout);
            in.close();
        }
        zout.flush();
        zout.closeEntry();
        delete();
    }
public HttpResponse executeHttp(final HttpUriRequest request, final int expectedCode) throws ClientProtocolException, IOException, HttpException {
        final HttpResponse response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() != expectedCode) {
            throw newHttpException(request, response);
        }
        return response;
    }
public HttpResponse executeHttp(final HttpUriRequest request, final int beginExpectedCode, final int endExpectedCode) throws ClientProtocolException, IOException, HttpException {
        final HttpResponse response = httpClient.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode < beginExpectedCode || statusCode >= endExpectedCode) {
            throw newHttpException(request, response);
        }
        return response;
    }
public static int getContentLength(URL urlFileLocation) {
        HttpURLConnection connFile = null;
        int iFileSize = -1;
        try {
            connFile = (HttpURLConnection) urlFileLocation.openConnection();
            connFile.setDoInput(true);
            InputStream is = connFile.getInputStream();
            iFileSize = connFile.getContentLength();
            is.close();
            connFile.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return iFileSize;
    }
private void writeResponse(final Collection<? extends Resource> resources, final HttpServletResponse response) throws IOException {
        for (final Resource resource : resources) {
            InputStream in = null;
            try {
                in = resource.getInputStream();
                final OutputStream out = response.getOutputStream();
                final long bytesCopied = IOUtils.copyLarge(in, out);
                if (bytesCopied < 0L) throw new StreamCorruptedException("Bad number of copied bytes (" + bytesCopied + ") for resource=" + resource.getFilename());
                if (logger.isDebugEnabled()) logger.debug("writeResponse(" + resource.getFile() + ") copied " + bytesCopied + " bytes");
            } finally {
                if (in != null) in.close();
            }
        }
    }
public void setPilot(PilotData pilotData) throws UsernameNotValidException {
        try {
            if (pilotData.username.trim().equals("") || pilotData.password.trim().equals("")) throw new UsernameNotValidException(1, "Username or password missing");
            PreparedStatement psta;
            if (pilotData.id == 0) {
                psta = jdbc.prepareStatement("INSERT INTO pilot " + "(name, address1, address2, zip, city, state, country, birthdate, " + "pft_theory, pft, medical, passenger, instructor, loc_language, " + "loc_country, loc_variant, username, password, id) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
                pilotData.id = Sequence.nextVal("pilot_id", jdbc);
            } else {
                psta = jdbc.prepareStatement("UPDATE pilot SET " + "name = ?, address1 = ?, address2 = ?, " + "zip = ?, city = ?, state = ?, country = ?, birthdate = ?, pft_theory = ?," + "pft = ?, medical = ?, passenger = ?, instructor = ?, loc_language = ?, " + "loc_country = ?, loc_variant = ?, username = ?, password = ? " + "WHERE id = ?");
            }
            psta.setString(1, pilotData.name);
            psta.setString(2, pilotData.address1);
            psta.setString(3, pilotData.address2);
            psta.setString(4, pilotData.zip);
            psta.setString(5, pilotData.city);
            psta.setString(6, pilotData.state);
            psta.setString(7, pilotData.country);
            if (pilotData.birthdate != null) psta.setLong(8, pilotData.birthdate.getTime()); else psta.setNull(8, java.sql.Types.INTEGER);
            if (pilotData.pft_theory != null) psta.setLong(9, pilotData.pft_theory.getTime()); else psta.setNull(9, java.sql.Types.INTEGER);
            if (pilotData.pft != null) psta.setLong(10, pilotData.pft.getTime()); else psta.setNull(10, java.sql.Types.INTEGER);
            if (pilotData.medical != null) psta.setLong(11, pilotData.medical.getTime()); else psta.setNull(11, java.sql.Types.INTEGER);
            if (pilotData.passenger) psta.setString(12, "Y"); else psta.setString(12, "N");
            if (pilotData.instructor) psta.setString(13, "Y"); else psta.setString(13, "N");
            psta.setString(14, pilotData.loc_language);
            psta.setString(15, pilotData.loc_country);
            psta.setString(16, pilotData.loc_variant);
            psta.setString(17, pilotData.username);
            psta.setString(18, pilotData.password);
            psta.setInt(19, pilotData.id);
            psta.executeUpdate();
            jdbc.commit();
        } catch (SQLException sql) {
            jdbc.rollback();
            sql.printStackTrace();
            throw new UsernameNotValidException(2, "Username allready exist");
        }
    }
public static String generateHash(String key) {
        key += "use_your_key_here";
        MessageDigest md;
        try {
            md = java.security.MessageDigest.getInstance("MD5");
            md.reset();
            md.update(key.getBytes());
            byte[] bytes = md.digest();
            StringBuffer buff = new StringBuffer();
            for (int l = 0; l < bytes.length; l++) {
                String hx = Integer.toHexString(0xFF & bytes[l]);
                if (hx.length() == 1) buff.append("0");
                buff.append(hx);
            }
            return buff.toString().trim();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
public HttpEntity execute(final HttpRequestBase request) throws IOException, ClientProtocolException {
        final HttpResponse response = mClient.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK | statusCode == HttpStatus.SC_CREATED) {
            return response.getEntity();
        }
        return null;
    }
protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
        PreparedStatement preStat = null;
        StringBuffer sqlStat = new StringBuffer();
        DmsRelationalWord tmpDmsRelationalWord = (DmsRelationalWord) ((DmsRelationalWord) obj).clone();
        synchronized (dbConn) {
            try {
                Integer nextID = getNextPrimaryID();
                Timestamp currTime = Utility.getCurrentTimestamp();
                sqlStat.append("INSERT ");
                sqlStat.append("INTO   DMS_RELATIONAL_WORD(ID, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE, WORD, PARENT_ID, TYPE) ");
                sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
                preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                setPrepareStatement(preStat, 1, nextID);
                setPrepareStatement(preStat, 2, tmpDmsRelationalWord.getRecordStatus());
                setPrepareStatement(preStat, 3, new Integer(0));
                setPrepareStatement(preStat, 4, tmpDmsRelationalWord.getCreatorID());
                setPrepareStatement(preStat, 5, currTime);
                setPrepareStatement(preStat, 6, tmpDmsRelationalWord.getUpdaterID());
                setPrepareStatement(preStat, 7, currTime);
                if (tmpDmsRelationalWord.getWord() == null || "".equals(tmpDmsRelationalWord.getWord().trim())) {
                    return null;
                }
                setPrepareStatement(preStat, 8, tmpDmsRelationalWord.getWord());
                setPrepareStatement(preStat, 9, tmpDmsRelationalWord.getParentID());
                setPrepareStatement(preStat, 10, tmpDmsRelationalWord.getType());
                preStat.executeUpdate();
                tmpDmsRelationalWord.setID(nextID);
                tmpDmsRelationalWord.setCreatorID(tmpDmsRelationalWord.getCreatorID());
                tmpDmsRelationalWord.setCreateDate(currTime);
                tmpDmsRelationalWord.setUpdaterID(tmpDmsRelationalWord.getUpdaterID());
                tmpDmsRelationalWord.setUpdateDate(currTime);
                tmpDmsRelationalWord.setUpdateCount(new Integer(0));
                tmpDmsRelationalWord.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsRelationalWord.getCreatorID()));
                tmpDmsRelationalWord.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsRelationalWord.getUpdaterID()));
                dbConn.commit();
                return (tmpDmsRelationalWord);
            } catch (Exception e) {
                try {
                    dbConn.rollback();
                } catch (Exception ee) {
                }
                log.error(e, e);
                throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
            } finally {
                try {
                    preStat.close();
                } catch (Exception ignore) {
                } finally {
                    preStat = null;
                }
            }
        }
    }
public static void copyFile(File src, File dest) throws IOException {
        FileInputStream fIn;
        FileOutputStream fOut;
        FileChannel fIChan, fOChan;
        long fSize;
        MappedByteBuffer mBuf;
        fIn = new FileInputStream(src);
        fOut = new FileOutputStream(dest);
        fIChan = fIn.getChannel();
        fOChan = fOut.getChannel();
        fSize = fIChan.size();
        mBuf = fIChan.map(FileChannel.MapMode.READ_ONLY, 0, fSize);
        fOChan.write(mBuf);
        fIChan.close();
        fIn.close();
        fOChan.close();
        fOut.close();
    }
public static Test suite() throws Exception {
        java.net.URL url = ClassLoader.getSystemResource("host0.jndi.properties");
        java.util.Properties host0JndiProps = new java.util.Properties();
        host0JndiProps.load(url.openStream());
        java.util.Properties systemProps = System.getProperties();
        systemProps.putAll(host0JndiProps);
        System.setProperties(systemProps);
        TestSuite suite = new TestSuite();
        suite.addTest(new TestSuite(T05DTMInterpositionUnitTestCase.class));
        TestSetup wrapper = new JBossTestSetup(suite) {

            protected void setUp() throws Exception {
                super.setUp();
                deploy("dtmpassthrough2dtm.jar");
            }

            protected void tearDown() throws Exception {
                undeploy("dtmpassthrough2dtm.jar");
                super.tearDown();
            }
        };
        return wrapper;
    }
private void open() throws IOException {
            if (in != null) return;
            try {
                con = url.openConnection();
                in = con.getInputStream();
            } catch (IOException e) {
                if (cached.exists()) {
                    LOG.fine("Falling back to cached copy of wiki file " + url);
                    in = new FileInputStream(cached);
                    con = null;
                    return;
                }
                throw e;
            }
            try {
                tmp = new File(cached.getAbsolutePath() + ".tmp");
                tmp.getParentFile().mkdirs();
                out = new FileOutputStream(tmp);
            } catch (IOException e) {
                LOG.fine("can't write cached copy of wiki file " + url);
            }
        }