semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void loadJar(final String extName, final String url, final String fileName, final IProgressListener pl) throws Exception {
        pl.setName(fileName);
        pl.setProgress(0);
        pl.setFinished(false);
        pl.setStarted(true);
        String installDirName = extDir + File.separator + extName;
        Log.log("extension installation directory: " + installDirName);
        File installDir = new File(installDirName);
        if (!installDir.exists()) {
            if (!installDir.mkdirs()) {
                throw new Exception("ExtensionLoader.loadJar: Cannot create install directory: " + installDirName);
            }
        }
        URL downloadURL = new URL(url + fileName);
        File jarFile = new File(installDirName, fileName);
        File indexFile = null;
        long urlTimeStamp = downloadURL.openConnection().getLastModified();
        String indexFileName = "";
        int idx = fileName.lastIndexOf(".");
        if (idx > 0) {
            indexFileName = fileName.substring(0, idx);
        } else {
            indexFileName = fileName;
        }
        indexFileName = indexFileName + ".idx";
        Log.log("index filename: " + indexFileName);
        boolean isDirty = true;
        if (jarFile.exists()) {
            Log.log("extensionfile already exists: " + fileName);
            indexFile = new File(installDir, indexFileName);
            if (indexFile.exists()) {
                Log.log("indexfile already exists");
                long cachedTimeStamp = readTimeStamp(indexFile);
                isDirty = !(cachedTimeStamp == urlTimeStamp);
                Log.log("cached file dirty: " + isDirty + ", url timestamp: " + urlTimeStamp + " cache stamp: " + cachedTimeStamp);
            } else {
                Log.log("indexfile doesn't exist, assume cache is dirty");
            }
        }
        if (isDirty) {
            if (jarFile.exists()) {
                if (indexFile != null && indexFile.exists()) {
                    Log.log("deleting old index file");
                    indexFile.delete();
                }
                indexFile = new File(installDirName, indexFileName);
                Log.log("deleting old cached file");
                jarFile.delete();
            }
            downloadJar(downloadURL, jarFile, pl);
            indexFile = new File(installDir, indexFileName);
            Log.log("writing timestamp to index file");
            writeTimeStamp(indexFile, urlTimeStamp);
        }
        addJar(jarFile);
    }
public String sendRequest(HttpRequest request) throws IOException, AuthenticationException, RedmineException, NotFoundException {
        logger.debug(request.getRequestLine().toString());
        DefaultHttpClient httpclient = HttpUtil.getNewHttpClient();
        configureProxy(httpclient);
        if (login != null) {
            final String credentials = String.valueOf(Base64Encoder.encode((login + ':' + password).getBytes(CHARSET)));
            request.addHeader("Authorization", "Basic: " + credentials);
        }
        request.addHeader("Accept-Encoding", "gzip,deflate");
        HttpResponse httpResponse = httpclient.execute((HttpUriRequest) request);
        int responseCode = httpResponse.getStatusLine().getStatusCode();
        if (responseCode == HttpStatus.SC_UNAUTHORIZED) {
            throw new AuthenticationException("Authorization error. Please check if you provided a valid API access key or Login and Password and REST API service is enabled on the server.");
        }
        if (responseCode == HttpStatus.SC_FORBIDDEN) {
            throw new AuthenticationException("Forbidden. Please check the user has proper permissions.");
        }
        HttpEntity responseEntity = httpResponse.getEntity();
        String responseBody = EntityUtils.toString(responseEntity);
        if (responseCode == HttpStatus.SC_NOT_FOUND) {
            throw new NotFoundException("Server returned '404 not found'. response body:" + responseBody);
        }
        if (responseCode == HttpStatus.SC_UNPROCESSABLE_ENTITY) {
            List<String> errors = RedmineXMLParser.parseErrors(responseBody);
            throw new RedmineException(errors);
        }
        httpclient.getConnectionManager().shutdown();
        return responseBody;
    }
@Override
    public HttpResponse execute() throws IOException {
        if (this.method == HttpMethod.GET) {
            String url = this.toString();
            if (url.length() > this.cutoff) {
                if (log.isLoggable(Level.FINER)) log.finer("URL length " + url.length() + " too long, converting GET to POST: " + url);
                String rebase = this.baseURL + "?method=GET";
                return this.execute(HttpMethod.POST, rebase);
            }
        }
        return super.execute();
    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        long t0 = System.currentTimeMillis();
        String id = request.getRequestURI().split("/")[3];
        Song song = manager.find(id);
        if (song != null) {
            if (song.getArtwork()) {
                if (log.isDebugEnabled()) log.debug("song has embedded artwork");
                try {
                    AudioFile af = AudioFileIO.read(new File(song.getFile()));
                    Tag tag = af.getTag();
                    Artwork aw = tag.getFirstArtwork();
                    byte[] bytes = aw.getBinaryData();
                    response.setStatus(HttpServletResponse.SC_OK);
                    response.setContentType(aw.getMimeType());
                    response.getOutputStream().write(bytes);
                } catch (Exception e) {
                    log.warn(e.getMessage());
                }
            } else {
                if (log.isDebugEnabled()) log.debug("search in directory");
                File directory = new File(song.getFile()).getParentFile();
                File[] files = directory.listFiles(filter);
                if (files != null && files.length > 0) {
                    File file = files[0];
                    String type = FilenameUtils.getExtension(file.getName()).toLowerCase();
                    if (type.startsWith("jp")) type = "jpeg";
                    String mime = "image/" + type;
                    response.setStatus(HttpServletResponse.SC_OK);
                    response.setContentType(mime);
                    FileInputStream stream = new FileInputStream(file);
                    try {
                        IOUtils.copy(stream, response.getOutputStream());
                    } catch (IOException e) {
                        log.warn(e.getMessage());
                    } finally {
                        IOUtils.closeQuietly(stream);
                    }
                } else {
                    if (log.isDebugEnabled()) log.debug("image not found: " + id + ", sending redirect: " + redirect);
                    response.sendRedirect(redirect);
                }
            }
        } else {
            log.info("song not found: " + id);
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
        long t1 = System.currentTimeMillis();
        log.info("request: " + id + " duration: " + (t1 - t0) + "ms");
    }
private String getFanFouMessage(int pageNo) throws IOException {
        URL url = new URL("http://api.fanfou.com/statuses/user_timeline.json?page=" + pageNo);
        HttpURLConnection request = (HttpURLConnection) url.openConnection();
        request.setDoOutput(true);
        request.setRequestMethod("GET");
        String basicAuth = Base64.encode((getUsername() + ":" + getPassword()).getBytes());
        request.addRequestProperty("Authorization", "Basic " + basicAuth);
        System.out.println("Sending request...");
        request.connect();
        System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        String b = null;
        StringBuffer sb = new StringBuffer();
        while ((b = reader.readLine()) != null) {
            sb.append(b);
        }
        return sb.toString();
    }
public Item doGiveCommentsOnFeedback(String itemId, String comments, boolean approved) throws UnsupportedEncodingException, IOException {
        log(INFO, "Give comments on feedback: Item id=" + itemId);
        String sessionId = (String) RuntimeAccess.getInstance().getSession().getAttribute("SESSION_ID");
        DefaultHttpClient httpclient = new DefaultHttpClient();
        GiveCommentsOnFeedbackRequest request = new GiveCommentsOnFeedbackRequest();
        request.setItemID(itemId);
        request.setSessionId(sessionId);
        request.setComments(comments);
        request.setApproved(approved);
        XStream writer = new XStream();
        writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        writer.alias("GiveCommentsOnFeedbackRequest", GiveCommentsOnFeedbackRequest.class);
        XStream reader = new XStream();
        reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
        reader.alias("GiveCommentsOnFeedbackResponse", GiveCommentsOnFeedbackResponse.class);
        String strRequest = URLEncoder.encode(reader.toXML(request), "UTF-8");
        HttpPost httppost = new HttpPost(MewitProperties.getMewitUrl() + "/resources/giveCommentsOnFeedback?REQUEST=" + strRequest);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = URLDecoder.decode(EntityUtils.toString(entity), "UTF-8");
            GiveCommentsOnFeedbackResponse oResponse = (GiveCommentsOnFeedbackResponse) reader.fromXML(result);
            return oResponse.getItem();
        }
        return null;
    }
public static void main(String[] args) throws Exception {
        String infile = "C:\\copy.sql";
        String outfile = "C:\\copy.txt";
        FileInputStream fin = new FileInputStream(infile);
        FileOutputStream fout = new FileOutputStream(outfile);
        FileChannel fcin = fin.getChannel();
        FileChannel fcout = fout.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            buffer.clear();
            int r = fcin.read(buffer);
            if (r == -1) {
                break;
            }
            buffer.flip();
            fcout.write(buffer);
        }
    }
public static String[] findClassesInPackage(String packageName, List<String> included, List<String> excluded) throws IOException {
        String packageOnly = packageName;
        boolean recursive = false;
        if (packageName.endsWith(".*")) {
            packageOnly = packageName.substring(0, packageName.lastIndexOf(".*"));
            recursive = true;
        }
        List<String> vResult = new ArrayList<String>();
        String packageDirName = packageOnly.replace('.', '/');
        Enumeration<URL> dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
        while (dirs.hasMoreElements()) {
            URL url = dirs.nextElement();
            String protocol = url.getProtocol();
            if (!matchTestClasspath(url, packageDirName, recursive)) {
                continue;
            }
            if ("file".equals(protocol)) {
                findClassesInDirPackage(packageOnly, included, excluded, URLDecoder.decode(url.getFile(), "UTF-8"), recursive, vResult);
            } else if ("jar".equals(protocol)) {
                JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile();
                Enumeration<JarEntry> entries = jar.entries();
                while (entries.hasMoreElements()) {
                    JarEntry entry = entries.nextElement();
                    String name = entry.getName();
                    if (name.charAt(0) == '/') {
                        name = name.substring(1);
                    }
                    if (name.startsWith(packageDirName)) {
                        int idx = name.lastIndexOf('/');
                        if (idx != -1) {
                            packageName = name.substring(0, idx).replace('/', '.');
                        }
                        Utils.log("PackageUtils", 4, "Package name is " + packageName);
                        if ((idx != -1) || recursive) {
                            if (name.endsWith(".class") && !entry.isDirectory()) {
                                String className = name.substring(packageName.length() + 1, name.length() - 6);
                                Utils.log("PackageUtils", 4, "Found class " + className + ", seeing it if it's included or excluded");
                                includeOrExcludeClass(packageName, className, included, excluded, vResult);
                            }
                        }
                    }
                }
            }
        }
        String[] result = vResult.toArray(new String[vResult.size()]);
        return result;
    }
@Override
    protected Void doInBackground(String... urls) {
        Log.d("ParseTask", "Getting URL " + urls[0]);
        try {
            XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
            reader.setContentHandler(mParser);
            reader.parse(new InputSource(new URL(urls[0]).openStream()));
        } catch (Exception e) {
            if (mCallback != null) mCallback.OnFailure(new ApiResponseObject(ApiResponse.RESPONSE_CRITICAL_FAILURE, e.getLocalizedMessage()));
        }
        return null;
    }
public final int sendMetaData(FileInputStream fis) throws Exception {
            try {
                UUID uuid = UUID.randomUUID();
                HttpClient client = new SSLHttpClient();
                StringBuilder builder = new StringBuilder(mServer).append("?cmd=meta").append("&id=" + uuid);
                HttpPost method = new HttpPost(builder.toString());
                String fileName = uuid + ".metadata";
                FileInputStreamPart part = new FileInputStreamPart("data", fileName, fis);
                MultipartEntity requestContent = new MultipartEntity(new Part[] { part });
                method.setEntity(requestContent);
                HttpResponse response = client.execute(method);
                int code = response.getStatusLine().getStatusCode();
                if (code == HttpStatus.SC_OK) {
                    return 0;
                } else {
                    return -1;
                }
            } catch (Exception e) {
                throw new Exception("send meta data", e);
            }
        }
public TVRageShowInfo(String xmlShowName) {
        String[] tmp, tmp2;
        String line = "";
        this.usrShowName = xmlShowName;
        try {
            URL url = new URL("http://www.tvrage.com/quickinfo.php?show=" + xmlShowName.replaceAll(" ", "%20"));
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = in.readLine()) != null) {
                tmp = line.split("@");
                if (tmp[0].equals("Show Name")) showName = tmp[1];
                if (tmp[0].equals("Show URL")) showURL = tmp[1];
                if (tmp[0].equals("Latest Episode")) {
                    StringTokenizer st = new StringTokenizer(tmp[1], "^");
                    for (int i = 0; st.hasMoreTokens(); i++) {
                        if (i == 0) {
                            tmp2 = st.nextToken().split("x");
                            latestSeasonNum = tmp2[0];
                            latestEpisodeNum = tmp2[1];
                            if (latestSeasonNum.charAt(0) == '0') latestSeasonNum = latestSeasonNum.substring(1);
                        } else if (i == 1) latestTitle = st.nextToken().replaceAll("&", "and"); else latestAirDate = st.nextToken();
                    }
                }
                if (tmp[0].equals("Next Episode")) {
                    StringTokenizer st = new StringTokenizer(tmp[1], "^");
                    for (int i = 0; st.hasMoreTokens(); i++) {
                        if (i == 0) {
                            tmp2 = st.nextToken().split("x");
                            nextSeasonNum = tmp2[0];
                            nextEpisodeNum = tmp2[1];
                            if (nextSeasonNum.charAt(0) == '0') nextSeasonNum = nextSeasonNum.substring(1);
                        } else if (i == 1) nextTitle = st.nextToken().replaceAll("&", "and"); else nextAirDate = st.nextToken();
                    }
                }
                if (tmp[0].equals("Status")) status = tmp[1];
                if (tmp[0].equals("Airtime")) airTime = tmp[1];
            }
            in.close();
            url = new URL(showURL);
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = in.readLine()) != null) {
                if (line.indexOf("<b>Latest Episode: </b>") > -1) {
                    tmp = line.split("'>");
                    if (tmp[2].indexOf(':') > -1) {
                        tmp = tmp[2].split(":");
                        latestSeriesNum = tmp[0];
                    }
                } else if (line.indexOf("<b>Next Episode: </b>") > -1) {
                    tmp = line.split("'>");
                    if (tmp[2].indexOf(':') > -1) {
                        tmp = tmp[2].split(":");
                        nextSeriesNum = tmp[0];
                    }
                }
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
public void patch() throws IOException {
        if (mods.isEmpty()) {
            return;
        }
        IOUtils.copy(new FileInputStream(Paths.getMinecraftJarPath()), new FileOutputStream(new File(Paths.getMinecraftBackupPath())));
        JarFile mcjar = new JarFile(Paths.getMinecraftJarPath());
    }
public ASDGrammarReader(String fileName, boolean includeCoords) throws IOException, MalformedURLException {
        includePixelCoords = includeCoords;
        fileName = fileName.trim();
        urlConnection = null;
        urlStream = null;
        if (fileName.substring(0, 5).equalsIgnoreCase("http:")) {
            URL fileURL = new URL(fileName);
            urlConnection = (HttpURLConnection) fileURL.openConnection();
            urlStream = urlConnection.getInputStream();
            reader = new ASDTokenReader(new BufferedReader(new InputStreamReader(urlStream)));
        } else reader = new ASDTokenReader(new FileReader(fileName));
    }
public static boolean checkVersion(String vers) throws IOException {
        try {
            String tmp = "";
            URL url = new URL("http://rbmsoft.com.br/apis/ql/index.php?url=null&versao=" + vers);
            BufferedInputStream buf = new BufferedInputStream(url.openStream());
            int dado = 0;
            char letra;
            while ((dado = buf.read()) != -1) {
                letra = (char) dado;
                tmp += letra;
            }
            if (tmp.contains("FALSE")) {
                return false;
            } else if (tmp.contains("TRUE")) {
                new UpdateCheck().updateDialog();
                return true;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return false;
    }
private static void readServicesFromUrl(Collection<String> list, URL url) throws IOException {
        InputStream in = url.openStream();
        try {
            if (in == null) return;
            BufferedReader r = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            while (true) {
                String line = r.readLine();
                if (line == null) break;
                int idx = line.indexOf('#');
                if (idx != -1) line = line.substring(0, idx);
                line = line.trim();
                if (line.length() == 0) continue;
                list.add(line);
            }
        } finally {
            try {
                if (in != null) in.close();
            } catch (Throwable ignore) {
            }
        }
    }
public void connect() throws IOException {
        try {
            URL url = new URL(pluginUrl);
            connection = (HttpURLConnection) url.openConnection();
            sendNotification(DownloadState.CONNECTION_ESTABLISHED);
            contentLength = connection.getContentLength();
            sendNotification(DownloadState.CONTENT_LENGTH_SET);
            downloadedBytes = 0;
        } catch (java.io.IOException e) {
            e.printStackTrace();
            throw e;
        }
    }
private void copyFileToDir(MyFile file, MyFile to, wlPanel panel) throws IOException {
        Utilities.print("started copying " + file.getAbsolutePath() + "\n");
        FileOutputStream fos = new FileOutputStream(new File(to.getAbsolutePath()));
        FileChannel foc = fos.getChannel();
        FileInputStream fis = new FileInputStream(new File(file.getAbsolutePath()));
        FileChannel fic = fis.getChannel();
        Date d1 = new Date();
        long amount = foc.transferFrom(fic, rest, fic.size() - rest);
        fic.close();
        foc.force(false);
        foc.close();
        Date d2 = new Date();
        long time = d2.getTime() - d1.getTime();
        double secs = time / 1000.0;
        double rate = amount / secs;
        frame.getStatusArea().append(secs + "s " + "amount: " + Utilities.humanReadable(amount) + " rate: " + Utilities.humanReadable(rate) + "/s\n", "black");
        panel.updateView();
    }
private static String processStr(String srcStr, String sign) throws NoSuchAlgorithmException, NullPointerException {
        if (null == srcStr) {
            throw new java.lang.NullPointerException("��Ҫ���ܵ��ַ�ΪNull");
        }
        MessageDigest digest;
        String algorithm = "MD5";
        String result = "";
        digest = MessageDigest.getInstance(algorithm);
        digest.update(srcStr.getBytes());
        byte[] byteRes = digest.digest();
        int length = byteRes.length;
        for (int i = 0; i < length; i++) {
            result = result + byteHEX(byteRes[i], sign);
        }
        return result;
    }