semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public String readURL(String urlLocation, ArrayList headers, RenderEngine c) throws Exception {
        URL url = null;
        HttpURLConnection conn = null;
        InputStream istream = null;
        try {
            url = new URL(urlLocation);
            conn = (HttpURLConnection) url.openConnection();
        } catch (Exception e) {
            throw new Exception("Soap is unable to retrieve URL for '" + urlLocation + "': " + e.getMessage());
        }
        loadCookies(urlLocation, conn, c);
        if (headers != null) {
            for (int i = 0; i < headers.size(); i++) {
                String header = (String) headers.get(i);
                String key = header.substring(0, header.indexOf(":"));
                String value = header.substring(header.indexOf(":") + 2);
                Debug.log("Adding new request header '" + key + "'='" + value + "'");
                conn.setRequestProperty(key, value);
            }
        }
        Debug.debug("Set to use GET, URL=" + urlLocation);
        try {
            istream = conn.getInputStream();
        } catch (Exception e) {
            Debug.debug("Unable to capture input stream: " + e.getMessage());
            throw new Exception("Unable to capture input stream from URL '" + urlLocation + "': " + e.getMessage());
        }
        Debug.debug("'GET' - Got input stream.");
        if (conn.getContentLength() == -1) {
            Debug.debug("Content length = unknown");
        } else {
            Debug.debug("Content length = " + conn.getContentLength());
        }
        byte data[] = null;
        int curPos = 0, contentLength = conn.getContentLength();
        if (conn.getContentLength() == -1) {
            String byteSize = NodeUtil.walkNodeTree(Server.getConfig(), "//configuration/object[@type='engine.tunable']/property[@type='engine.unknowncontentsize']/@value");
            if (byteSize == null) {
                contentLength = 4096;
            } else {
                contentLength = Integer.parseInt(byteSize);
            }
            Debug.debug("Content length unknown.  Allowing fuzz of " + contentLength + " bytes.");
        }
        data = new byte[contentLength];
        try {
            int dataRead = 0;
            while ((dataRead = istream.read(data, curPos, contentLength - curPos)) != -1) {
                if (dataRead == 0) {
                    break;
                }
                curPos += dataRead;
            }
        } catch (Exception e) {
            throw new Exception("Soap is unable to read data from HTTP connection: " + e.getMessage());
        }
        try {
            istream.close();
            conn.disconnect();
        } catch (MalformedURLException e) {
            throw new Exception("Soap request to site '" + urlLocation + "' is invalid: " + e.getMessage());
        } catch (IOException e) {
            throw new Exception("Soap request to site '" + urlLocation + "' failed to connect.");
        }
        String dataOut = new String(data);
        int counter = 0;
        data = null;
        istream = null;
        conn = null;
        url = null;
        return dataOut.trim();
    }
public static String getPasswordHash(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes());
            byte[] byteData = md.digest();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            logger.log(Level.SEVERE, "Unknow error in hashing password", e);
            return "Unknow error, check system log";
        }
    }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/jar");
        byte[] bufor = new byte[BUF_LEN];
        ServletContext context = getServletContext();
        URL url = context.getResource(FILE_NAME);
        InputStream in = url.openStream();
        OutputStream out = response.getOutputStream();
        while (in.read(bufor) != -1) out.write(bufor);
        in.close();
        out.close();
    }
private Date getArtifactFileLastUpdate(Artifact artifact) {
        URL url = null;
        try {
            url = new URL(baseUrl + artifact.getOrganisationName().replaceAll("\\.", "/") + "/" + artifact.getName().replaceAll("\\.", "/") + "/" + artifact.getVersion() + "/");
        } catch (MalformedURLException e) {
            log.warn("cannot retrieve last modifcation date", e);
            return null;
        }
        URLConnection urlConnection = null;
        InputStream inputStream = null;
        try {
            urlConnection = url.openConnection();
            inputStream = urlConnection.getInputStream();
        } catch (FileNotFoundException e) {
            log.warn("cannot retrieve last modifcation date", e);
            return null;
        } catch (IOException e) {
            log.warn("cannot retrieve last modifcation date", e);
            return null;
        }
        StringBuffer buffer = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
        } catch (IOException e) {
            log.warn("cannot retrieve last modifcation date", e);
            return new Date(0);
        }
        Pattern pattern = Pattern.compile("<a href=\"" + artifact.getName() + "-" + artifact.getVersion() + ".jar\">" + artifact.getName() + "-" + artifact.getVersion() + ".jar</a> *(\\d{2}-[a-zA-Z]{3}-\\d{4} \\d{2}:\\d{2})");
        Matcher m = pattern.matcher(buffer);
        if (m.find()) {
            String dateStr = m.group(1);
            try {
                return mavenDateFormateur.parse(dateStr);
            } catch (ParseException e) {
                log.warn("cannot retrieve last modifcation date", e);
                return new Date(0);
            }
        }
        log.warn("cannot retrieve last modifcation date");
        return new Date(0);
    }
@Override
    public List<Type> getArtifactTypes(String organisationName, String artifactName, String version) {
        if (cache != null) {
            Date d;
            try {
                d = cache.getTypesLastUpdate(organisationName, artifactName, version);
                if (d.compareTo(cacheExpirationDate) >= 0) {
                    return cache.getTypes(organisationName, artifactName, version);
                }
            } catch (CacheAccessException e) {
                log.warn("cannot access cache", e);
            }
        }
        List<Type> types = new ArrayList<Type>();
        String urlString = generateUrlString(organisationName, artifactName, version, Type.JAR);
        try {
            new URL(urlString).openStream();
            types.add(Type.JAR);
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        urlString = generateUrlString(organisationName, artifactName, version, Type.SRC);
        try {
            new URL(urlString).openStream();
            types.add(Type.SRC);
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        urlString = generateUrlString(organisationName, artifactName, version, Type.WAR);
        try {
            new URL(urlString).openStream();
            types.add(Type.WAR);
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        urlString = generateUrlString(organisationName, artifactName, version, Type.ZIP);
        try {
            new URL(urlString).openStream();
            types.add(Type.ZIP);
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        if (cache != null) {
            try {
                cache.updateTypes(organisationName, artifactName, version, types);
            } catch (CacheAccessException e) {
                log.warn("cannot access cache", e);
            }
        }
        return types;
    }
public void onCreate() {
        window = ((Window) getFellow("win"));
        userName = ((Textbox) getFellow("user"));
        password = ((Textbox) getFellow("password"));
        session = window.getDesktop().getSession();
        if (Executions.getCurrent().getParameter("login") != null) {
            login = Executions.getCurrent().getParameter("login");
            session.setAttribute("login", login);
        }
        if (Executions.getCurrent().getParameter("password") != null) {
            passwordu = Executions.getCurrent().getParameter("password");
        }
        if (Executions.getCurrent().getParameter("option") != null) {
            option = Executions.getCurrent().getParameter("option");
            session.setAttribute("option", option);
        }
        if (Executions.getCurrent().getParameter("organization") != null) {
            organization = Executions.getCurrent().getParameter("organization");
            session.setAttribute("organization", organization);
        }
        if (Executions.getCurrent().getParameter("project") != null) {
            project = Executions.getCurrent().getParameter("project");
            session.setAttribute("project", project);
        }
        if (login != null) {
            User user = UserDAO.getUserByUserName(login);
            if (user != null) {
                String encodedPassword = null;
                try {
                    MessageDigest digest = MessageDigest.getInstance("MD5");
                    digest.update(user.getPassword().getBytes());
                    BASE64Encoder encoder = new BASE64Encoder();
                    encodedPassword = encoder.encode(digest.digest());
                } catch (Exception e) {
                }
                if (passwordu.compareTo(encodedPassword) == 0) {
                    session.setAttribute("user", user);
                    session.setAttribute("numero", 5);
                    session.setAttribute("option", option);
                    session.setAttribute("organization", organization);
                    session.setAttribute("project", project);
                    Executions.sendRedirect("menu.zul");
                }
            }
        }
    }
public boolean requestServerModifications(UUID sessionId, OutputStream out) throws SynchronizationException {
        HttpClient client = new SSLHttpClient();
        StringBuilder builder = new StringBuilder(url).append("?" + SESSION_PARAM + "=" + sessionId).append("&" + CMD_PARAM + "=" + CMD_SERVERMODIF);
        HttpGet method = httpGetMethod(builder.toString());
        try {
            HttpResponse response = client.execute(method);
            Header header = response.getFirstHeader(HEADER_NAME);
            if (header != null && HEADER_VALUE.equals(header.getValue())) {
                int code = response.getStatusLine().getStatusCode();
                if (code == HttpStatus.SC_OK) {
                    long expectedLength = response.getEntity().getContentLength();
                    InputStream is = response.getEntity().getContent();
                    FileUtils.writeInFile(is, out, expectedLength);
                    return true;
                } else {
                    throw new SynchronizationException("Command 'receive' : HTTP error code returned." + code, SynchronizationException.ERROR_RECEIVE);
                }
            } else {
                throw new SynchronizationException("HTTP header is invalid", SynchronizationException.ERROR_RECEIVE);
            }
        } catch (Exception e) {
            throw new SynchronizationException("Command 'receive' -> ", e, SynchronizationException.ERROR_RECEIVE);
        }
    }
public boolean searchEntity(String login, String password, String searcheId, OutputStream os) throws SynchronizationException {
        HttpClient client = new SSLHttpClient();
        try {
            StringBuilder builder = new StringBuilder(url).append("?" + CMD_PARAM + "=" + CMD_SEARCH).append("&" + LOGIN_PARAM + "=" + URLEncoder.encode(login, "UTF-8")).append("&" + PASSWD_PARAM + "=" + URLEncoder.encode(password, "UTF-8")).append("&" + SEARCH_PARAM + "=" + searcheId);
            HttpGet method = httpGetMethod(builder.toString());
            HttpResponse response = client.execute(method);
            Header header = response.getFirstHeader(HEADER_NAME);
            if (header != null && HEADER_VALUE.equals(HEADER_VALUE)) {
                int code = response.getStatusLine().getStatusCode();
                if (code == HttpStatus.SC_OK) {
                    long expectedLength = response.getEntity().getContentLength();
                    InputStream is = response.getEntity().getContent();
                    FileUtils.writeInFile(is, os, expectedLength);
                    return true;
                } else {
                    throw new SynchronizationException("Command 'search' : HTTP error code returned." + code, SynchronizationException.ERROR_SEARCH);
                }
            } else {
                throw new SynchronizationException("HTTP header is invalid", SynchronizationException.ERROR_SEARCH);
            }
        } catch (Exception e) {
            throw new SynchronizationException("Command 'search' -> ", e, SynchronizationException.ERROR_SEARCH);
        }
    }
private String getServerData(String returnString) {
        InputStream is = null;
        String result = "";
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("usuario", Login.usuario));
        nameValuePairs.add(new BasicNameValuePair("amigoABorrar", amigoABorrar.trim()));
        nameValuePairs.add(new BasicNameValuePair("grupo", MisGrupos.seleccion.trim()));
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(returnString);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
        } catch (Exception e) {
            Log.e("AmigosPorGrupo", "Error en la conexion http " + e.toString());
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            String line = reader.readLine();
            is.close();
            result = line.trim().toString();
            Log.d("AmigosPorGrupo", "Longitud line: " + line.trim().length());
        } catch (Exception e) {
            Log.e("AmigosPorGrupo", "Error converting result " + e.toString());
        }
        Log.d("AmigosPorGrupo", "Funciono json" + result);
        return result;
    }
public void saveProjectFile(File aFile) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        File destDir = new File(theProjectsDirectory, sdf.format(Calendar.getInstance().getTime()));
        if (destDir.mkdirs()) {
            File outFile = new File(destDir, "project.xml");
            try {
                FileChannel sourceChannel = new FileInputStream(aFile).getChannel();
                FileChannel destinationChannel = new FileOutputStream(outFile).getChannel();
                sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
                sourceChannel.close();
                destinationChannel.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                aFile.delete();
            }
        }
    }
public byte[] loadRaw(String ontologyUrl) throws IOException {
        URL url = new URL(ontologyUrl);
        InputStream is = url.openStream();
        final int BUFFER_SIZE = 1024;
        byte[] buffer = new byte[BUFFER_SIZE];
        ByteArrayOutputStream ontologyBytes = new ByteArrayOutputStream();
        for (; ; ) {
            int bytesRead = is.read(buffer);
            if (bytesRead <= 0) break;
            ontologyBytes.write(buffer, 0, bytesRead);
        }
        return ontologyBytes.toByteArray();
    }
public void setRandom(boolean random) {
        this.random = random;
        if (random) {
            possibleScores = new int[NUM_SCORES];
            for (int i = 0; i < NUM_SCORES - 1; i++) {
                getRandomScore: while (true) {
                    int score = (int) (Math.random() * 20) + 1;
                    for (int j = 0; j < i; j++) {
                        if (score == possibleScores[j]) {
                            continue getRandomScore;
                        }
                    }
                    possibleScores[i] = score;
                    break;
                }
            }
            possibleScores[NUM_SCORES - 1] = 25;
            boolean sorted = false;
            while (!sorted) {
                sorted = true;
                for (int i = 0; i < NUM_SCORES - 1; i++) {
                    if (possibleScores[i] > possibleScores[i + 1]) {
                        int t = possibleScores[i];
                        possibleScores[i] = possibleScores[i + 1];
                        possibleScores[i + 1] = t;
                        sorted = false;
                    }
                }
            }
            setPossibleScores(possibleScores);
        }
    }
private boolean writeResource(PluginProxy eclipseInstallPlugin, ResourceProxy translation, LocaleProxy locale) throws Exception {
        String translationResourceName = determineTranslatedResourceName(translation, locale);
        String pluginNameInDirFormat = eclipseInstallPlugin.getName().replace(Messages.getString("Characters_period"), File.separator);
        if (translation.getRelativePath().contains(pluginNameInDirFormat)) {
            return writeResourceToBundleClasspath(translation, locale);
        } else if (translationResourceName.contains(File.separator)) {
            String resourcePath = translationResourceName.substring(0, translationResourceName.lastIndexOf(File.separatorChar));
            File resourcePathDirectory = new File(directory.getPath() + File.separatorChar + resourcePath);
            resourcePathDirectory.mkdirs();
        }
        File fragmentResource = new File(directory.getPath() + File.separatorChar + translationResourceName);
        File translatedResource = new File(translation.getFileResource().getAbsolutePath());
        FileChannel inputChannel = new FileInputStream(translatedResource).getChannel();
        FileChannel outputChannel = new FileOutputStream(fragmentResource).getChannel();
        inputChannel.transferTo(0, inputChannel.size(), outputChannel);
        inputChannel.close();
        outputChannel.close();
        return true;
    }
public static void save(String packageName, ArrayList<byte[]> fileContents, ArrayList<String> fileNames) throws Exception {
        String dirBase = Util.JAVA_DIR + File.separator + packageName;
        File packageDir = new File(dirBase);
        if (!packageDir.exists()) {
            boolean created = packageDir.mkdir();
            if (!created) {
                File currentPath = new File(".");
                throw new Exception("Directory " + packageName + " could not be created. Current directory: " + currentPath.getAbsolutePath());
            }
        }
        for (int i = 0; i < fileContents.size(); i++) {
            File file = new File(Util.JAVA_DIR + File.separator + fileNames.get(i));
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(fileContents.get(i));
            fos.flush();
            fos.close();
        }
        for (int i = 0; i < fileNames.size(); i++) {
            File fileSrc = new File(Util.JAVA_DIR + File.separator + fileNames.get(i));
            File fileDst = new File(dirBase + File.separator + fileNames.get(i));
            BufferedReader reader = new BufferedReader(new FileReader(fileSrc));
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileDst));
            writer.append("package " + packageName + ";\n");
            String line = "";
            while ((line = reader.readLine()) != null) writer.append(line + "\n");
            writer.flush();
            writer.close();
            reader.close();
        }
    }
public static void copy(File from, File to) {
        if (from.getAbsolutePath().equals(to.getAbsolutePath())) {
            return;
        }
        FileInputStream is = null;
        FileOutputStream os = null;
        try {
            is = new FileInputStream(from);
            os = new FileOutputStream(to);
            int read = -1;
            byte[] buffer = new byte[10000];
            while ((read = is.read(buffer)) > 0) {
                os.write(buffer, 0, read);
            }
        } catch (Exception e) {
            throw new RuntimeException();
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
            try {
                os.close();
            } catch (Exception e) {
            }
        }
    }
public static File copyFile(File fileToCopy, File copiedFile) {
        BufferedInputStream in = null;
        BufferedOutputStream outWriter = null;
        if (!copiedFile.exists()) {
            try {
                copiedFile.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
                return null;
            }
        }
        try {
            in = new BufferedInputStream(new FileInputStream(fileToCopy), 4096);
            outWriter = new BufferedOutputStream(new FileOutputStream(copiedFile), 4096);
            int c;
            while ((c = in.read()) != -1) outWriter.write(c);
            in.close();
            outWriter.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return copiedFile;
    }
public byte[] getHash(String plaintext) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        digest.reset();
        digest.update(salt.getBytes("UTF-8"));
        return digest.digest(plaintext.getBytes("UTF-8"));
    }
public static long toFile(final DigitalObject object, final File file) {
        try {
            FileOutputStream fOut = new FileOutputStream(file);
            long bytesCopied = IOUtils.copyLarge(object.getContent().getInputStream(), fOut);
            fOut.close();
            return bytesCopied;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }
private static File getZipAsFile(DigitalObject digOb) {
        String folderName = randomizeFileName(getFolderNameFromDigObject(digOb));
        File tmpFolder = new File(utils_tmp, folderName);
        File zip = null;
        try {
            FileUtils.forceMkdir(tmpFolder);
            zip = new File(tmpFolder, getFileNameFromDigObject(digOb, null));
            FileOutputStream out = new FileOutputStream(zip);
            IOUtils.copyLarge(digOb.getContent().getInputStream(), out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return zip;
    }