semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String getFileContents(String path) {
        BufferedReader buffReader = null;
        InputStream stream = null;
        if (path.indexOf("://") != -1) {
            URL url = null;
            try {
                url = new URL(path);
            } catch (MalformedURLException e) {
                LOGGER.warn(String.format("Malformed URL: \"%s\"", path));
            }
            if (url == null) {
                throw new DeveloperError(String.format("Cannot create URL from path: \"%s\"", path), new NullPointerException());
            }
            try {
                String encoding = Characters.getDeclaredXMLEncoding(url);
                stream = url.openStream();
                buffReader = new BufferedReader(new InputStreamReader(stream, encoding));
            } catch (IOException e) {
                LOGGER.warn(String.format("I/O error trying to read \"%s\"", path));
            }
        } else {
            File toRead = null;
            try {
                toRead = getExistingFile(path);
            } catch (FileNotFoundException e) {
                throw new UserError(new FileNotFoundException(path));
            }
            if (toRead.isAbsolute()) {
                String parent = toRead.getParent();
                try {
                    workingDirectory.push(URLTools.createValidURL(parent));
                } catch (FileNotFoundException e) {
                    throw new DeveloperError(String.format("Created an invalid parent file: \"%s\".", parent), e);
                }
            }
            if (toRead.exists() && !toRead.isDirectory()) {
                String _path = toRead.getAbsolutePath();
                try {
                    String encoding = Characters.getDeclaredXMLEncoding(URLTools.createValidURL(_path));
                    stream = new FileInputStream(_path);
                    buffReader = new BufferedReader(new InputStreamReader(stream, encoding));
                } catch (IOException e) {
                    LOGGER.warn(String.format("I/O error trying to read \"%s\"", _path));
                    return null;
                }
            } else {
                assert toRead.exists() : "getExistingFile() returned a non-existent file";
                if (toRead.isDirectory()) {
                    throw new UserError(new FileAlreadyExistsAsDirectoryException(toRead));
                }
            }
        }
        StringBuilder result = new StringBuilder();
        String line;
        if (buffReader != null && stream != null) {
            try {
                while ((line = buffReader.readLine()) != null) {
                    result.append(line);
                }
                buffReader.close();
                stream.close();
            } catch (IOException e) {
                LOGGER.warn(String.format("I/O error trying to read \"%s\"", path));
                return null;
            }
        }
        return result.toString();
    }
public void testCryptHash() {
        Log.v("Test", "[*] testCryptHash()");
        String testStr = "Hash me";
        byte messageDigest[];
        MessageDigest digest = null;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(testStr.getBytes());
            messageDigest = digest.digest();
            digest.digest(testStr.getBytes());
            digest = java.security.MessageDigest.getInstance("SHA1");
            digest.update(testStr.getBytes());
            messageDigest = digest.digest();
            digest = null;
            digest = java.security.MessageDigest.getInstance("SHA1");
            digest.update(imei.getBytes());
            messageDigest = digest.digest();
            hashedImei = this.toHex(messageDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
public void testNetworkHTTP() {
        Log.v("Test", "[*] testNetworkHTTP()");
        URL url = null;
        HttpURLConnection urlConnection = null;
        try {
            url = new URL("http://code.google.com/p/droidbox/");
            urlConnection = (HttpURLConnection) url.openConnection();
            BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            @SuppressWarnings("unused") String line = "";
            while ((line = rd.readLine()) != null) ;
            url = new URL("http://pjlantz.com/imei.php?imei=" + hashedImei);
            urlConnection = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            while ((line = rd.readLine()) != null) ;
            url = new URL("http://pjlantz.com/phone.php?phone=" + phoneNbr);
            urlConnection = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            while ((line = rd.readLine()) != null) ;
            url = new URL("http://pjlantz.com/msg.php?msg=" + msg.replace(" ", "+"));
            urlConnection = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            url = new URL("http://pjlantz.com/file.php?file=" + fileContent.replace(" ", "+"));
            urlConnection = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            while ((line = rd.readLine()) != null) ;
            url = new URL("http://pjlantz.com/app.php?installed=" + installedApps.replace(" ", "+"));
            urlConnection = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            while ((line = rd.readLine()) != null) ;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            urlConnection.disconnect();
        }
    }
public static void main(String[] args) {
        try {
            URL url = new URL(args[0]);
            HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
            httpCon.setDoOutput(true);
            httpCon.setRequestMethod("PUT");
            OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
            out.write("fatal error");
            out.close();
            System.out.println("end");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public synchronized void write() throws IOException {
        ZipOutputStream jar = new ZipOutputStream(new FileOutputStream(jarPath));
        int index = className.lastIndexOf('.');
        String packageName = className.substring(0, index);
        String clazz = className.substring(index + 1);
        String directory = packageName.replace('.', '/');
        ZipEntry dummyClass = new ZipEntry(directory + "/" + clazz + ".class");
        jar.putNextEntry(dummyClass);
        ClassGen classgen = new ClassGen(getClassName(), "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
        byte[] bytes = classgen.getJavaClass().getBytes();
        jar.write(bytes);
        jar.closeEntry();
        ZipEntry synthFile = new ZipEntry(directory + "/synth.xml");
        jar.putNextEntry(synthFile);
        Comment comment = new Comment("Generated by SynthBuilder from L2FProd.com");
        Element root = new Element("synth");
        root.addAttribute(new Attribute("version", "1"));
        root.appendChild(comment);
        Element defaultStyle = new Element("style");
        defaultStyle.addAttribute(new Attribute("id", "default"));
        Element defaultFont = new Element("font");
        defaultFont.addAttribute(new Attribute("name", "SansSerif"));
        defaultFont.addAttribute(new Attribute("size", "12"));
        defaultStyle.appendChild(defaultFont);
        Element defaultState = new Element("state");
        defaultStyle.appendChild(defaultState);
        root.appendChild(defaultStyle);
        Element bind = new Element("bind");
        bind.addAttribute(new Attribute("style", "default"));
        bind.addAttribute(new Attribute("type", "region"));
        bind.addAttribute(new Attribute("key", ".*"));
        root.appendChild(bind);
        doc = new Document(root);
        imagesToCopy = new HashMap();
        ComponentStyle[] styles = config.getStyles();
        for (ComponentStyle element : styles) {
            write(element);
        }
        Serializer writer = new Serializer(jar);
        writer.setIndent(2);
        writer.write(doc);
        writer.flush();
        jar.closeEntry();
        for (Iterator iter = imagesToCopy.keySet().iterator(); iter.hasNext(); ) {
            String element = (String) iter.next();
            File pathToImage = (File) imagesToCopy.get(element);
            ZipEntry image = new ZipEntry(directory + "/" + element);
            jar.putNextEntry(image);
            FileInputStream input = new FileInputStream(pathToImage);
            int read = -1;
            while ((read = input.read()) != -1) {
                jar.write(read);
            }
            input.close();
            jar.flush();
            jar.closeEntry();
        }
        jar.flush();
        jar.close();
    }
private String makeLoginRequest(URL url) throws IOException {
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("POST");
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.setUseCaches(false);
        urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        StringBuilder content = new StringBuilder();
        content.append("Email=").append(URLEncoder.encode(EMAIL, "UTF-8"));
        content.append("&Passwd=").append(URLEncoder.encode(PASSWORD, "UTF-8"));
        content.append("&service=").append(URLEncoder.encode(SERVICE, "UTF-8"));
        content.append("&source=").append(URLEncoder.encode("Google Base data API", "UTF-8"));
        OutputStream outputStream = urlConnection.getOutputStream();
        outputStream.write(content.toString().getBytes("UTF-8"));
        outputStream.close();
        int responseCode = urlConnection.getResponseCode();
        InputStream inputStream;
        if (responseCode == HttpURLConnection.HTTP_OK) {
            inputStream = urlConnection.getInputStream();
        } else {
            inputStream = urlConnection.getErrorStream();
        }
        return toString(inputStream);
    }
public static String generateMD5(String str) {
        String hashword = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            hashword = hash.toString(16);
        } catch (NoSuchAlgorithmException nsae) {
            logger.log(Level.SEVERE, null, nsae);
        }
        return hashword;
    }
public List<String> query(String query) throws IOException {
        List<String> list = new LinkedList<String>();
        query = URLEncoder.encode(query, "UTF-8");
        String queryurl = baseurl + "?type=tuples&lang=itql&format=csv&query=" + query;
        URL url = new URL(queryurl);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = reader.readLine();
        while (line != null) {
            list.add(line);
            line = reader.readLine();
        }
        reader.close();
        return list;
    }
public long create(long mimeTypeId, long sanId) throws SQLException {
        long fileId = 0;
        DataSource ds = getDataSource(DEFAULT_DATASOURCE);
        Connection conn = ds.getConnection();
        try {
            conn.setAutoCommit(false);
            Statement stmt = conn.createStatement();
            stmt.execute(NEXT_FILE_ID);
            ResultSet rs = stmt.getResultSet();
            while (rs.next()) {
                fileId = rs.getLong(NEXTVAL);
            }
            PreparedStatement pstmt = conn.prepareStatement(INSERT_FILE);
            pstmt.setLong(1, fileId);
            pstmt.setLong(2, mimeTypeId);
            pstmt.setLong(3, sanId);
            pstmt.setLong(4, WORKFLOW_ATTENTE_VALIDATION);
            int nbrow = pstmt.executeUpdate();
            if (nbrow == 0) {
                throw new SQLException();
            }
            conn.commit();
            closeRessources(conn, pstmt);
        } catch (SQLException e) {
            log.error("Can't FileDAOImpl.create " + e.getMessage());
            conn.rollback();
            throw e;
        }
        return fileId;
    }
public FileBean create(MimeTypeBean mimeType, SanBean san) throws SQLException {
        long fileId = 0;
        DataSource ds = getDataSource(DEFAULT_DATASOURCE);
        Connection conn = ds.getConnection();
        try {
            conn.setAutoCommit(false);
            Statement stmt = conn.createStatement();
            stmt.execute(NEXT_FILE_ID);
            ResultSet rs = stmt.getResultSet();
            while (rs.next()) {
                fileId = rs.getLong(NEXTVAL);
            }
            PreparedStatement pstmt = conn.prepareStatement(INSERT_FILE);
            pstmt.setLong(1, fileId);
            pstmt.setLong(2, mimeType.getId());
            pstmt.setLong(3, san.getId());
            pstmt.setLong(4, WORKFLOW_ATTENTE_VALIDATION);
            int nbrow = pstmt.executeUpdate();
            if (nbrow == 0) {
                throw new SQLException();
            }
            conn.commit();
            closeRessources(conn, pstmt);
        } catch (SQLException e) {
            log.error("Can't FileDAOImpl.create " + e.getMessage());
            conn.rollback();
            throw e;
        }
        FileBean fileBean = new FileBean();
        return fileBean;
    }
public int deleteFile(Integer[] fileID) throws SQLException {
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Connection conn = null;
        int nbrow = 0;
        try {
            DataSource ds = getDataSource(DEFAULT_DATASOURCE);
            conn = ds.getConnection();
            conn.setAutoCommit(false);
            if (log.isDebugEnabled()) {
                log.debug("FileDAOImpl.deleteFile() " + DELETE_FILES_LOGIC);
            }
            for (int i = 0; i < fileID.length; i++) {
                pstmt = conn.prepareStatement(DELETE_FILES_LOGIC);
                pstmt.setInt(1, fileID[i].intValue());
                nbrow = pstmt.executeUpdate();
            }
        } catch (SQLException e) {
            conn.rollback();
            log.error("FileDAOImpl.deleteFile() : erreur technique", e);
            throw e;
        } finally {
            conn.commit();
            closeRessources(conn, pstmt, rs);
        }
        return nbrow;
    }
public static void copyFile(File src, File dest, int bufSize, boolean force) throws IOException {
        if (dest.exists()) if (force) dest.delete(); else throw new IOException("Cannot overwrite existing file: " + dest.getName());
        byte[] buffer = new byte[bufSize];
        int read = 0;
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            while (true) {
                read = in.read(buffer);
                if (read == -1) break;
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) try {
                in.close();
            } finally {
                if (out != null) out.close();
            }
        }
    }
public static final TreeSet<String> getValues(String baseurl, String rftId, String svcId) {
        TreeSet<String> values = new TreeSet<String>();
        String[] fragments = rftId.split("/");
        String e_repoUri = null;
        String e_svcId = null;
        try {
            e_repoUri = URLEncoder.encode(rftId, "UTF-8");
            e_svcId = URLEncoder.encode(svcId, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("UnsupportedEncodingException resulted attempting to encode " + rftId);
        }
        String openurl = baseurl + "/" + fragments[2] + "/openurl-aDORe7" + "?rft_id=" + e_repoUri + "&svc_id=" + e_svcId + "&url_ver=Z39.88-2004";
        log.info("Obtaining Content Values from: " + openurl);
        try {
            URL url = new URL(openurl);
            long s = System.currentTimeMillis();
            URLConnection conn = url.openConnection();
            int timeoutMs = 1000 * 60 * 30;
            conn.setConnectTimeout(timeoutMs);
            conn.setReadTimeout(timeoutMs);
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            log.info("Query Time: " + (System.currentTimeMillis() - s) + "ms");
            String line;
            while ((line = in.readLine()) != null) {
                values.add(line);
            }
            in.close();
        } catch (Exception ex) {
            log.error("problem with openurl:" + openurl + ex.getMessage());
            throw new RuntimeException(ex);
        }
        return values;
    }
public static void copyFile(File src, File dst) throws IOException {
        if (T.t) T.info("Copying " + src + " -> " + dst + "...");
        FileInputStream in = new FileInputStream(src);
        FileOutputStream out = new FileOutputStream(dst);
        byte buf[] = new byte[40 * KB];
        int read;
        while ((read = in.read(buf)) != -1) {
            out.write(buf, 0, read);
        }
        out.flush();
        out.close();
        in.close();
        if (T.t) T.info("File copied.");
    }
private synchronized void createFTPConnection() throws FTPBrowseException {
        ftpClient = new FTPClient();
        try {
            InetAddress inetAddress = InetAddress.getByName(url.getHost());
            if (url.getPort() == -1) {
                ftpClient.connect(inetAddress);
            } else {
                ftpClient.connect(inetAddress, url.getPort());
            }
            if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                throw new FTPBrowseException(ftpClient.getReplyString());
            }
            if (null != passwordAuthentication) {
                ftpClient.login(passwordAuthentication.getUserName(), new StringBuffer().append(passwordAuthentication.getPassword()).toString());
            }
            if (url.getPath().length() > 0) {
                ftpClient.changeWorkingDirectory(url.getPath());
            }
            homeDirectory = ftpClient.printWorkingDirectory();
        } catch (UnknownHostException e) {
            throw new FTPBrowseException(e.getMessage());
        } catch (SocketException e) {
            throw new FTPBrowseException(e.getMessage());
        } catch (FTPBrowseException e) {
            throw e;
        } catch (IOException e) {
            throw new FTPBrowseException(e.getMessage());
        }
    }
public static String send(String method, String url, Map<String, String> paramMap, File file, String encoding) throws HttpServerStatusException {
        Log.i(TAG, "url:" + url);
        boolean bVisitOK = false;
        int tryCnt = 0;
        String result = "";
        while (!bVisitOK && (tryCnt++ < MAXTRYCNT)) {
            try {
                HttpRequestBase base = getExecuteMethod(method, url, paramMap, file);
                HttpResponse response = client.execute(base, localContext);
                int status = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    result = readByteStream(entity.getContent(), encoding);
                    entity.consumeContent();
                }
                if (status == 200) {
                    return result;
                } else {
                    throw new HttpServerStatusException(status, result);
                }
            } catch (HttpServerStatusException e) {
                throw e;
            } catch (IllegalStateException e) {
                bVisitOK = false;
                Log.e(TAG, e.toString());
            } catch (IOException e) {
                bVisitOK = false;
                Log.e(TAG, e.toString());
            }
        }
        return result;
    }
public static HttpEntity sendHE(String method, String url, Map<String, String> paramMap, String encoding) throws HttpServerStatusException {
        Log.i(TAG, "url:" + url);
        boolean bVisitOK = false;
        int tryCnt = 0;
        while (!bVisitOK && (tryCnt++ < MAXTRYCNT)) {
            try {
                HttpRequestBase base = getExecuteMethod(method, url, paramMap, null);
                HttpResponse response = client.execute(base, localContext);
                int status = response.getStatusLine().getStatusCode();
                if (status == 200) {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        return entity;
                    }
                } else {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                    throw new HttpServerStatusException(status, "");
                }
            } catch (HttpServerStatusException e) {
                throw e;
            } catch (IllegalStateException e) {
                bVisitOK = false;
                Log.e(TAG, e.toString());
            } catch (IOException e) {
                bVisitOK = false;
                Log.e(TAG, e.toString());
            }
        }
        return null;
    }
private String postXml(String url, String soapAction, String xml) {
        try {
            URLConnection conn = new URL(url).openConnection();
            if (conn instanceof HttpURLConnection) {
                HttpURLConnection hConn = (HttpURLConnection) conn;
                hConn.setRequestMethod("POST");
            }
            conn.setConnectTimeout(this.connectionTimeout);
            conn.setReadTimeout(this.connectionTimeout);
            conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            conn.setRequestProperty("Accept", "application/soap+xml, text/*");
            if (soapAction != null) {
                conn.setRequestProperty("SOAPAction", soapAction);
            }
            conn.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
            out.write(xml);
            out.close();
            BufferedReader resp = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder buf = new StringBuilder();
            String str;
            while ((str = resp.readLine()) != null) {
                buf.append(str);
            }
            return buf.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
public void postProcess() throws StopWriterVisitorException {
        dxfWriter.postProcess();
        try {
            FileChannel fcinDxf = new FileInputStream(fTemp).getChannel();
            FileChannel fcoutDxf = new FileOutputStream(m_Fich).getChannel();
            DriverUtilities.copy(fcinDxf, fcoutDxf);
            fTemp.delete();
        } catch (FileNotFoundException e) {
            throw new StopWriterVisitorException(getName(), e);
        } catch (IOException e) {
            throw new StopWriterVisitorException(getName(), e);
        }
    }
private boolean connect() {
        try {
            this.ftpClient.connect(this.server, this.port);
            this.ftpClient.login(this.username, this.password);
            return true;
        } catch (IOException iOException) {
            return false;
        }
    }