semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String readData(URL url) {
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer responseBuffer = new StringBuffer();
            String line;
            while ((line = in.readLine()) != null) {
                responseBuffer.append(line);
            }
            in.close();
            return new String(responseBuffer);
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;
    }
public static String encrypt(String text) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            throw new WebDocRuntimeException(ex);
        }
        md.update(text.getBytes());
        BigInteger hash = new BigInteger(1, md.digest());
        return hash.toString(HEX);
    }
private Date fetchLastModifiedDate(String archName) {
        Date modifdate = null;
        URL url = null;
        try {
            url = new URL(jEdit.getProperty(OOO_DICTS_PROP) + archName + ".zip");
        } catch (MalformedURLException mfue) {
            Log.log(Log.ERROR, HunspellDictsManager.class, "Invalid archive name : " + archName);
            GUIUtilities.error(null, "spell-check-hunspell-error-fetch", new String[] { mfue.getMessage() });
        }
        if (url != null) {
            try {
                URLConnection connect = url.openConnection();
                connect.connect();
                if (connect.getLastModified() == 0) {
                    Log.log(Log.ERROR, HunspellDictsManager.class, "no lastModifiedDate for " + archName);
                } else {
                    modifdate = new Date(connect.getLastModified());
                    System.out.println("Modif date :" + DateFormat.getInstance().format(modifdate));
                    return modifdate;
                }
            } catch (IOException ioe) {
                GUIUtilities.error(null, "spell-check-hunspell-error-fetch", new String[] { ioe.getMessage() });
                ioe.printStackTrace();
            }
        }
        return modifdate;
    }
public void invoke(String args[]) {
        System.err.println("invoked with args of size " + args.length);
        try {
            for (int i = 0; i < args.length; i++) {
                System.err.println("processing URL: " + args[i]);
                URL url = new URL(args[i]);
                AnnotatedLinearObjectParser parserObj = findParserForURL(url);
                if (parserObj == null) {
                    continue;
                }
                InputStream data = url.openStream();
                CompMapViewerWrapper wrapper = ((CompMapViewerProvider) sp).getWrapper();
                wrapper.parseIntoDataModel(data, new URLImpl(url.toString()), parserObj, false);
                JFrame f = wrapper.getViewer().getMainFrame();
                f.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void connect() throws ClientProtocolException, IOException {
        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity entity = httpResponse.getEntity();
        inputStream = entity.getContent();
        Header contentEncodingHeader = entity.getContentEncoding();
        if (contentEncodingHeader != null) {
            HeaderElement[] codecs = contentEncodingHeader.getElements();
            for (HeaderElement encoding : codecs) {
                if (encoding.getName().equalsIgnoreCase("gzip")) {
                    inputStream = new GZIPInputStream(inputStream);
                }
            }
        }
        inputStream = new BufferedInputStream(inputStream, 2048);
    }
public boolean backupFile(File oldFile, File newFile) {
        boolean isBkupFileOK = false;
        FileChannel sourceChannel = null;
        FileChannel targetChannel = null;
        try {
            sourceChannel = new FileInputStream(oldFile).getChannel();
            targetChannel = new FileOutputStream(newFile).getChannel();
            targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "IO exception occurred while copying file", e);
        } finally {
            if ((newFile != null) && (newFile.exists()) && (newFile.length() > 0)) {
                isBkupFileOK = true;
            }
            try {
                if (sourceChannel != null) {
                    sourceChannel.close();
                }
                if (targetChannel != null) {
                    targetChannel.close();
                }
            } catch (IOException e) {
                logger.log(Level.INFO, "closing channels failed");
            }
        }
        return isBkupFileOK;
    }
public String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance(SHA1);
        md.update(text.getBytes(CHAR_SET), 0, text.length());
        byte[] mdbytes = md.digest();
        return byteToHex(mdbytes);
    }
public void connect() throws SocketException, IOException {
        Log.i(TAG, "Test attempt login to " + ftpHostname + " as " + ftpUsername);
        ftpClient = new FTPClient();
        ftpClient.connect(this.ftpHostname, this.ftpPort);
        ftpClient.login(ftpUsername, ftpPassword);
        int reply = ftpClient.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            String error = "Login failure (" + reply + ") : " + ftpClient.getReplyString();
            Log.e(TAG, error);
            throw new IOException(error);
        }
    }
public void copyTo(String newname) throws IOException {
        FileChannel srcChannel = new FileInputStream(dosname).getChannel();
        FileChannel dstChannel = new FileOutputStream(newname).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public static String hashString(String sPassword) {
        if (sPassword == null || sPassword.equals("")) {
            return "empty:";
        } else {
            try {
                MessageDigest md = MessageDigest.getInstance("SHA-1");
                md.update(sPassword.getBytes("UTF-8"));
                byte[] res = md.digest();
                return "sha1:" + StringUtils.byte2hex(res);
            } catch (NoSuchAlgorithmException e) {
                return "plain:" + sPassword;
            } catch (UnsupportedEncodingException e) {
                return "plain:" + sPassword;
            }
        }
    }
public static byte[] wrapBMP(Image image) throws IOException {
        if (image.getOriginalType() != Image.ORIGINAL_BMP) throw new IOException("Only BMP can be wrapped in WMF.");
        InputStream imgIn;
        byte data[] = null;
        if (image.getOriginalData() == null) {
            imgIn = image.url().openStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int b = 0;
            while ((b = imgIn.read()) != -1) out.write(b);
            imgIn.close();
            data = out.toByteArray();
        } else data = image.getOriginalData();
        int sizeBmpWords = (data.length - 14 + 1) >>> 1;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        writeWord(os, 1);
        writeWord(os, 9);
        writeWord(os, 0x0300);
        writeDWord(os, 9 + 4 + 5 + 5 + (13 + sizeBmpWords) + 3);
        writeWord(os, 1);
        writeDWord(os, 14 + sizeBmpWords);
        writeWord(os, 0);
        writeDWord(os, 4);
        writeWord(os, META_SETMAPMODE);
        writeWord(os, 8);
        writeDWord(os, 5);
        writeWord(os, META_SETWINDOWORG);
        writeWord(os, 0);
        writeWord(os, 0);
        writeDWord(os, 5);
        writeWord(os, META_SETWINDOWEXT);
        writeWord(os, (int) image.height());
        writeWord(os, (int) image.width());
        writeDWord(os, 13 + sizeBmpWords);
        writeWord(os, META_DIBSTRETCHBLT);
        writeDWord(os, 0x00cc0020);
        writeWord(os, (int) image.height());
        writeWord(os, (int) image.width());
        writeWord(os, 0);
        writeWord(os, 0);
        writeWord(os, (int) image.height());
        writeWord(os, (int) image.width());
        writeWord(os, 0);
        writeWord(os, 0);
        os.write(data, 14, data.length - 14);
        if ((data.length & 1) == 1) os.write(0);
        writeDWord(os, 3);
        writeWord(os, 0);
        os.close();
        return os.toByteArray();
    }
private void readChildrenData() throws Exception {
        URL url;
        URLConnection connect;
        BufferedInputStream in;
        try {
            url = getURL("CHILDREN.TAB");
            connect = url.openConnection();
            InputStream ois = connect.getInputStream();
            if (ois == null) {
                concepts3 = new IntegerArray(1);
                return;
            }
            in = new BufferedInputStream(ois);
            int k1 = in.read();
            concepts3 = new IntegerArray(4096);
            StreamDecompressor sddocs = new StreamDecompressor(in);
            sddocs.ascDecode(k1, concepts3);
            int k2 = in.read();
            offsets3 = new IntegerArray(concepts3.cardinality() + 1);
            offsets3.add(0);
            StreamDecompressor sdoffsets = new StreamDecompressor(in);
            sdoffsets.ascDecode(k2, offsets3);
            in.close();
            url = getURL("CHILDREN");
            connect = url.openConnection();
            ois = connect.getInputStream();
            if (ois == null) {
                concepts3 = new IntegerArray(1);
                return;
            }
            in = new BufferedInputStream(ois);
            int length = connect.getContentLength();
            allChildren = new byte[length];
            in.read(allChildren);
            in.close();
        } catch (MalformedURLException e) {
            concepts3 = new IntegerArray(1);
        } catch (FileNotFoundException e2) {
            concepts3 = new IntegerArray(1);
        } catch (IOException e2) {
            concepts3 = new IntegerArray(1);
        }
    }
private void readFromDB() throws Exception {
        URL url;
        URLConnection connect;
        BufferedInputStream in = null;
        Schema schema = new Schema(base, indexDir, false);
        BtreeDictParameters params = new BtreeDictParameters(schema, "TMAP");
        params.readState();
        tmap = new BtreeDict(params);
        readChildrenData();
        url = getURL("DOCS.TAB");
        connect = url.openConnection();
        in = new BufferedInputStream(connect.getInputStream());
        int k1 = in.read();
        concepts = new IntegerArray(4096);
        StreamDecompressor sddocs = new StreamDecompressor(in);
        sddocs.ascDecode(k1, concepts);
        int k2 = in.read();
        offsets = new IntegerArray(concepts.cardinality() + 1);
        offsets.add(0);
        StreamDecompressor sdoffsets = new StreamDecompressor(in);
        sdoffsets.ascDecode(k2, offsets);
        in.close();
        url = getURL("DOCS");
        connect = url.openConnection();
        in = new BufferedInputStream(connect.getInputStream());
        ByteArrayOutputStream data = new ByteArrayOutputStream();
        byte[] buff = new byte[512];
        int i = 0;
        while ((i = in.read(buff)) != -1) {
            data.write(buff, 0, i);
        }
        allLists = data.toByteArray();
        in.close();
        url = getURL("OFFSETS");
        connect = url.openConnection();
        in = new BufferedInputStream(connect.getInputStream());
        k1 = in.read();
        documents = new IntegerArray(4096);
        sddocs = new StreamDecompressor(in);
        sddocs.ascDecode(k1, documents);
        k2 = in.read();
        offsets2 = new IntegerArray(documents.cardinality() + 1);
        sdoffsets = new StreamDecompressor(in);
        sdoffsets.ascDecode(k2, offsets2);
        int k3 = in.read();
        titles = new IntegerArray(documents.cardinality());
        StreamDecompressor sdtitles = new StreamDecompressor(in);
        sdtitles.decode(k3, titles);
        in.close();
        RAFFileFactory factory = RAFFileFactory.create();
        url = getURL("POSITIONS");
        positionsFile = factory.get(url, false);
    }
private static String getSuitableWCSVersion(String host, String _version) throws ConnectException, IOException {
        String request = WCSProtocolHandler.buildCapabilitiesSuitableVersionRequest(host, _version);
        String version = new String();
        StringReader reader = null;
        DataInputStream dis = null;
        try {
            URL url = new URL(request);
            byte[] buffer = new byte[1024];
            dis = new DataInputStream(url.openStream());
            dis.readFully(buffer);
            reader = new StringReader(new String(buffer));
            KXmlParser kxmlParser = null;
            kxmlParser = new KXmlParser();
            kxmlParser.setInput(reader);
            kxmlParser.nextTag();
            if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) {
                if ((kxmlParser.getName().compareTo(CapabilitiesTags.WCS_CAPABILITIES_ROOT1_0_0) == 0)) {
                    version = kxmlParser.getAttributeValue("", CapabilitiesTags.VERSION);
                }
            }
            reader.close();
            dis.close();
            return version;
        } catch (ConnectException conEx) {
            throw new ConnectException(conEx.getMessage());
        } catch (IOException ioEx) {
            throw new IOException(ioEx.getMessage());
        } catch (XmlPullParserException xmlEx) {
            xmlEx.printStackTrace();
            return "";
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (dis != null) {
                try {
                    dis.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
public static String encrypt(String text) throws NoSuchAlgorithmException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[32];
        try {
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
@Override
            protected IStatus run(final IProgressMonitor monitor) {
                try {
                    showTileInfo(remoteFileName, -1);
                    System.out.println("   connect " + host);
                    ftp.connect();
                    showTileInfo(remoteFileName, -2);
                    System.out.println("   login " + user + " " + password);
                    ftp.login(user, password);
                    System.out.println("   set passive mode");
                    ftp.setConnectMode(FTPConnectMode.PASV);
                    System.out.println("   set type binary");
                    ftp.setType(FTPTransferType.BINARY);
                    showTileInfo(remoteFileName, -3);
                    System.out.println("   chdir " + remoteFilePath);
                    ftp.chdir(remoteFilePath);
                    ftp.setProgressMonitor(new FTPProgressMonitor() {

                        public void bytesTransferred(final long count) {
                            tileInfoMgr.updateSRTMTileInfo(TileEventId.SRTM_DATA_LOADING_MONITOR, remoteFileName, count);
                        }
                    });
                    showTileInfo(remoteFileName, -4);
                    System.out.println("   get " + remoteFileName + " -> " + localName + " ...");
                    ftp.get(localName, remoteFileName);
                    System.out.println("   quit");
                    ftp.quit();
                } catch (final UnknownHostException e) {
                    return new Status(IStatus.ERROR, TourbookPlugin.PLUGIN_ID, IStatus.ERROR, NLS.bind(Messages.error_message_cannotConnectToServer, host), e);
                } catch (final SocketTimeoutException e) {
                    return new Status(IStatus.ERROR, TourbookPlugin.PLUGIN_ID, IStatus.ERROR, NLS.bind(Messages.error_message_timeoutWhenConnectingToServer, host), e);
                } catch (final Exception e) {
                    e.printStackTrace();
                    tileInfoMgr.updateSRTMTileInfo(TileEventId.SRTM_DATA_ERROR_LOADING, remoteFileName, 0);
                } finally {
                    tileInfoMgr.updateSRTMTileInfo(TileEventId.SRTM_DATA_END_LOADING, remoteFileName, 0);
                }
                return Status.OK_STATUS;
            }
public Document load(java.net.URL url) throws DOMTestLoadException {
        Document doc = null;
        Exception parseException = null;
        try {
            LoadErrorHandler errorHandler = new LoadErrorHandler();
            builder.setErrorHandler(errorHandler);
            doc = builder.parse(url.openStream(), url.toString());
            parseException = errorHandler.getFirstException();
        } catch (Exception ex) {
            parseException = ex;
        }
        builder.setErrorHandler(null);
        if (parseException != null) {
            throw new DOMTestLoadException(parseException);
        }
        return doc;
    }
public Point getCoordinates(String address, String city, String state, String country) {
        StringBuilder queryString = new StringBuilder();
        StringBuilder urlString = new StringBuilder();
        StringBuilder response = new StringBuilder();
        if (address != null) {
            queryString.append(address.trim().replaceAll(" ", "+"));
            queryString.append("+");
        }
        if (city != null) {
            queryString.append(city.trim().replaceAll(" ", "+"));
            queryString.append("+");
        }
        if (state != null) {
            queryString.append(state.trim().replaceAll(" ", "+"));
            queryString.append("+");
        }
        if (country != null) {
            queryString.append(country.replaceAll(" ", "+"));
        }
        urlString.append("http://maps.google.com/maps/geo?key=");
        urlString.append(key);
        urlString.append("&sensor=false&output=json&oe=utf8&q=");
        urlString.append(queryString.toString());
        try {
            URL url = new URL(urlString.toString());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            JSONObject root = (JSONObject) JSONValue.parse(response.toString());
            JSONObject placemark = (JSONObject) ((JSONArray) root.get("Placemark")).get(0);
            JSONArray coordinates = (JSONArray) ((JSONObject) placemark.get("Point")).get("coordinates");
            Point point = new Point();
            point.setLatitude((Double) coordinates.get(1));
            point.setLongitude((Double) coordinates.get(0));
            return point;
        } catch (MalformedURLException ex) {
            return null;
        } catch (NullPointerException ex) {
            return null;
        } catch (IOException ex) {
            return null;
        }
    }
private static void copyFile(File in, File out) throws Exception {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
private void initialize() {
        StringBuffer license = new StringBuffer();
        URL url;
        InputStreamReader in;
        BufferedReader reader;
        String str;
        JTextArea textArea;
        JButton button;
        GridBagConstraints c;
        setTitle("mibible License");
        setSize(600, 600);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new GridBagLayout());
        url = getClass().getClassLoader().getResource("LICENSE.txt");
        if (url == null) {
            license.append("Couldn't locate license file (LICENSE.txt).");
        } else {
            try {
                in = new InputStreamReader(url.openStream());
                reader = new BufferedReader(in);
                while ((str = reader.readLine()) != null) {
                    if (!str.equals("")) {
                        license.append(str);
                    }
                    license.append("\n");
                }
                reader.close();
            } catch (IOException e) {
                license.append("Error reading license file ");
                license.append("(LICENSE.txt):\n\n");
                license.append(e.getMessage());
            }
        }
        textArea = new JTextArea(license.toString());
        textArea.setEditable(false);
        c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0d;
        c.weighty = 1.0d;
        c.insets = new Insets(4, 5, 4, 5);
        getContentPane().add(new JScrollPane(textArea), c);
        button = new JButton("Close");
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        c = new GridBagConstraints();
        c.gridy = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.insets = new Insets(10, 10, 10, 10);
        getContentPane().add(button, c);
    }
public void testJob() {
        try {
            URL url = new URL("http://rickysql.gotoip3.com/mapp/admin/admin.do");
            url.openConnection();
            url.getContent();
            System.out.print("00");
        } catch (Exception e) {
            System.out.print("Daily data update exception:" + e);
        }
    }
@Override
    public String getMessageDigest() throws SarasvatiLoadException {
        if (messageDigest == null) {
            Collections.sort(nodes);
            Collections.sort(externals);
            try {
                MessageDigest digest = MessageDigest.getInstance("SHA1");
                digest.update(name.getBytes());
                for (XmlNode node : nodes) {
                    node.addToDigest(digest);
                }
                for (XmlExternal external : externals) {
                    external.addToDigest(digest);
                }
                messageDigest = SvUtil.getHexString(digest.digest());
            } catch (NoSuchAlgorithmException nsae) {
                throw new SarasvatiException("Unable to load SHA1 algorithm", nsae);
            }
        }
        return messageDigest;
    }
public static byte[] hash(final byte[] saltBefore, final String content, final byte[] saltAfter, final int repeatedHashingCount) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        if (content == null) return null;
        final MessageDigest digest = MessageDigest.getInstance(DIGEST);
        if (digestLength == -1) digestLength = digest.getDigestLength();
        for (int i = 0; i < repeatedHashingCount; i++) {
            if (i > 0) digest.update(digest.digest());
            digest.update(saltBefore);
            digest.update(content.getBytes(WebCastellumParameter.DEFAULT_CHARACTER_ENCODING.getValue()));
            digest.update(saltAfter);
        }
        return digest.digest();
    }