semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected boolean doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getPathInfo();
        if (!path.startsWith(alias)) {
            throw new ServletException("Path '" + path + "' does not start with registered alias '" + alias + "'");
        }
        String internal;
        if (alias.equals("/")) {
            internal = name + path;
        } else {
            internal = name + path.substring(alias.length(), path.length());
        }
        URL resource = httpContext.getResource(internal);
        if (resource == null) {
            return false;
        }
        String mimeType = servletContext.getMimeType(internal);
        if (mimeType != null) {
            response.setContentType(mimeType);
        }
        InputStream is = resource.openStream();
        OutputStream os = response.getOutputStream();
        IOUtils.copyAndClose(is, os);
        return true;
    }
private void exportJar(File root, List<File> list, Manifest manifest) throws Exception {
        JarOutputStream jarOut = null;
        FileInputStream fin = null;
        try {
            jarOut = new JarOutputStream(new FileOutputStream(jarFile), manifest);
            for (int i = 0; i < list.size(); i++) {
                String filename = list.get(i).getAbsolutePath();
                filename = filename.substring(root.getAbsolutePath().length() + 1);
                fin = new FileInputStream(list.get(i));
                JarEntry entry = new JarEntry(filename.replace('\\', '/'));
                jarOut.putNextEntry(entry);
                byte[] buf = new byte[4096];
                int read;
                while ((read = fin.read(buf)) != -1) {
                    jarOut.write(buf, 0, read);
                }
                jarOut.closeEntry();
                jarOut.flush();
            }
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (Exception e) {
                    ExceptionOperation.operate(e);
                }
            }
            if (jarOut != null) {
                try {
                    jarOut.close();
                } catch (Exception e) {
                }
            }
        }
    }
public static void main(String[] args) throws Exception {
        String st = "http://www.kmzlinks.com/redirect.asp?id=113&file=HeartShapedIsland.kmz";
        URL url = new URL(st);
        InputStream fis = null;
        if ("file".equals(url.getProtocol())) fis = new FileInputStream(url.getFile()); else if ("http".equals(url.getProtocol())) fis = url.openStream();
        ZipInputStream zis = new ZipInputStream(fis);
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " + entry);
            int count;
            byte data[] = new byte[BUFFER];
            FileOutputStream fos = new FileOutputStream(entry.getName());
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
            dest.flush();
            dest.close();
        }
        zis.close();
    }
public void load() throws IOException {
        File file = new File(filename);
        URL url = file.toURI().toURL();
        Properties temp = new Properties();
        temp.load(url.openStream());
        if (temp.getProperty("Width") != null) try {
            width = Integer.valueOf(temp.getProperty("Width"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Width - leaving as default: " + e);
        }
        if (temp.getProperty("Height") != null) try {
            height = Integer.valueOf(temp.getProperty("Height"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Height - leaving as default: " + e);
        }
        if (temp.getProperty("CircleRadius") != null) try {
            circleradius = Double.valueOf(temp.getProperty("CircleRadius"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Circle Radius - leaving as default: " + e);
        }
        ArrayList<Ellipse> calibrationcircleslist = new ArrayList<Ellipse>();
        int i = 0;
        while ((temp.getProperty("Circle" + i + "CenterX") != null) && (temp.getProperty("Circle" + i + "CenterY") != null)) {
            Point2d circlecenter = new Point2d(0, 0);
            circlecenter.x = Double.valueOf(temp.getProperty("Circle" + i + "CenterX"));
            circlecenter.y = Double.valueOf(temp.getProperty("Circle" + i + "CenterY"));
            Ellipse element = new Ellipse(circlecenter, circleradius, circleradius, 0);
            calibrationcircleslist.add(element);
            i++;
        }
        calibrationcircles = new Ellipse[0];
        calibrationcircles = calibrationcircleslist.toArray(calibrationcircles);
    }
public void method31() {
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = 0; i < anInt772 - 1; i++) if (anIntArray774[i] < anIntArray774[i + 1]) {
                int j = anIntArray774[i];
                anIntArray774[i] = anIntArray774[i + 1];
                anIntArray774[i + 1] = j;
                long l = aLongArray773[i];
                aLongArray773[i] = aLongArray773[i + 1];
                aLongArray773[i + 1] = l;
                flag = true;
            }
        }
    }
private void unzipData(ZipFile zipfile, ZipEntry entry) {
        if (entry.getName().equals("backUpExternalInfo.out")) {
            File outputFile = new File("temp", entry.getName());
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }
            try {
                BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
                BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
                IOUtils.copy(inputStream, outputStream);
                outputStream.close();
                inputStream.close();
            } catch (IOException e) {
                throw new BackupException(e.getMessage());
            }
        }
    }
@Override
    protected Object transform(Row inputs) throws FunctionException {
        StringBuffer buffer = new StringBuffer();
        for (IColumn c : inputs.getColumns()) {
            buffer.append(c.getValueAsString() + "|");
        }
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(buffer.toString().getBytes());
            byte[] hash = digest.digest();
            return getHex(hash);
        } catch (Exception e) {
            throw new FunctionException(e);
        }
    }
public static void extractFile(String input, String output) throws ZipException, IOException {
        FileReader reader = new FileReader(input);
        InputStream in = reader.getInputStream();
        OutputStream out = new FileOutputStream(new File(output));
        byte[] buf = new byte[512];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        reader.close();
        out.close();
    }
public static DataElement createMD5Sum(int type, String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(data.getBytes());
            byte[] dt = md.digest();
            return new DataElement(type, hexEncode(dt));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new DataElement(type);
    }
public static byte[] hash(String plainTextValue) {
        MessageDigest msgDigest;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
            msgDigest.update(plainTextValue.getBytes("UTF-8"));
            byte[] digest = msgDigest.digest();
            return digest;
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
static void invalidSlave(String msg, Socket sock) throws IOException {
        BufferedReader _sinp = null;
        PrintWriter _sout = null;
        try {
            _sout = new PrintWriter(sock.getOutputStream(), true);
            _sinp = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            _sout.println(msg);
            logger.info("NEW< " + msg);
            String txt = AsyncSlaveListener.readLine(_sinp, 30);
            String sname = "";
            String spass = "";
            String shash = "";
            try {
                String[] items = txt.split(" ");
                sname = items[1].trim();
                spass = items[2].trim();
                shash = items[3].trim();
            } catch (Exception e) {
                throw new IOException("Slave Inititalization Faailed");
            }
            String pass = sname + spass + _pass;
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            String hash = AsyncSlaveListener.hash2hex(md5.digest()).toLowerCase();
            if (!hash.equals(shash)) {
                throw new IOException("Slave Inititalization Faailed");
            }
        } catch (Exception e) {
        }
        throw new IOException("Slave Inititalization Faailed");
    }
public static String readAsString(final URL url) throws java.io.IOException {
        InputStream inputStream = url.openStream();
        try {
            return readAsString(inputStream);
        } finally {
            try {
                inputStream.close();
            } catch (Throwable t) {
            }
        }
    }
@Before
    public void BeforeTheTest() throws Exception {
        URL url = ProfileParserTest.class.getClassLoader().getResource("ca/uhn/hl7v2/conf/parser/tests/example_ack.xml");
        URLConnection conn = url.openConnection();
        InputStream instream = conn.getInputStream();
        if (instream == null) throw new Exception("can't find the xml file");
        BufferedReader in = new BufferedReader(new InputStreamReader(instream));
        int tmp = 0;
        StringBuffer buf = new StringBuffer();
        while ((tmp = in.read()) != -1) {
            buf.append((char) tmp);
        }
        profileString = buf.toString();
    }
private String getPrefsKey(String key) {
        try {
            if (MD5 == null) MD5 = MessageDigest.getInstance("MD5");
            MD5.reset();
            MD5.update(key.getBytes("UTF-8"));
            byte[] resultBytes = MD5.digest();
            return toHexString(resultBytes);
        } catch (Exception nsae) {
            return key;
        }
    }
public static void copy(File in, File out) throws IOException {
        FileChannel ic = new FileInputStream(in).getChannel();
        FileChannel oc = new FileOutputStream(out).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();
    }
public void run() {
        String s;
        s = "";
        try {
            URL url = new URL("http://www.m-w.com/dictionary/" + word);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while (((str = in.readLine()) != null) && (!stopped)) {
                s = s + str;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        Pattern pattern = Pattern.compile("Main Entry:.+?<br>(.+?)</td>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(s);
        java.io.StringWriter wr = new java.io.StringWriter();
        HTMLDocument doc = null;
        HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
        try {
            doc = (HTMLDocument) editor.getDocument();
        } catch (Exception e) {
        }
        System.out.println(wr);
        editor.setContentType("text/html");
        if (matcher.find()) try {
            kit.insertHTML(doc, editor.getCaretPosition(), "<HR>" + matcher.group(1) + "<HR>", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } else try {
            kit.insertHTML(doc, editor.getCaretPosition(), "<HR><FONT COLOR='RED'>NOT FOUND!!</FONT><HR>", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        button.setEnabled(true);
    }
public static boolean downloadFile(String url, String destination) throws Exception {
        BufferedInputStream bi = null;
        BufferedOutputStream bo = null;
        File destfile;
        java.net.URL fileurl;
        fileurl = new java.net.URL(url);
        bi = new BufferedInputStream(fileurl.openStream());
        destfile = new File(destination);
        if (!destfile.createNewFile()) {
            destfile.delete();
            destfile.createNewFile();
        }
        bo = new BufferedOutputStream(new FileOutputStream(destfile));
        int readedbyte;
        while ((readedbyte = bi.read()) != -1) {
            bo.write(readedbyte);
        }
        bi.close();
        bo.close();
        return true;
    }
public String encodePassword(String password, byte[] salt) throws Exception {
        if (salt == null) {
            salt = new byte[12];
            secureRandom.nextBytes(salt);
        }
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes("UTF8"));
        byte[] digest = md.digest();
        byte[] storedPassword = new byte[digest.length + 12];
        System.arraycopy(salt, 0, storedPassword, 0, 12);
        System.arraycopy(digest, 0, storedPassword, 12, digest.length);
        return new String(Base64.encode(storedPassword));
    }
private String sendMail() throws IOException {
        String msg = StringEscapeUtils.escapeHtml(message.getText());
        StringBuffer buf = new StringBuffer();
        buf.append(encode("n", name.getText()));
        buf.append("&").append(encode("e", email.getText()));
        buf.append("&").append(encode("r", recpt.getText()));
        buf.append("&").append(encode("m", msg));
        buf.append("&").append(encode("s", score));
        buf.append("&").append(encode("i", calcScoreImage()));
        buf.append("&").append(encode("c", digest(recpt.getText() + "_" + score)));
        URL url = new URL("http://www.enerjy.com/share/mailit.php");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter writer = null;
        BufferedReader reader = null;
        boolean haveOk = false;
        try {
            writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(buf.toString());
            writer.flush();
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            for (String line = reader.readLine(); null != line; line = reader.readLine()) {
                if (line.startsWith("err:")) {
                    return line.substring(4);
                } else if (line.equals("ok")) {
                    haveOk = true;
                }
            }
        } finally {
            StreamUtils.close(writer);
            StreamUtils.close(reader);
        }
        if (!haveOk) {
            return "The server did not return a response.";
        }
        return null;
    }
private static String digest(String val) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(val.trim().getBytes());
            byte[] digest = md.digest();
            StringBuffer buf = new StringBuffer();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b);
                int length = hexString.length();
                if (length > 2) {
                    hexString = hexString.substring(length - 2, length);
                } else if (length < 2) {
                    hexString = "0" + hexString;
                }
                buf.append(hexString);
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new EnerjyException("Could not create digest: MD5", e);
        }
    }
private String readScriptFromURL(URL context, String s) {
        Object content = null;
        URL url;
        try {
            url = new URL(context, s);
        } catch (MalformedURLException e) {
            return null;
        }
        try {
            content = url.getContent();
        } catch (UnknownServiceException e) {
            Class jar_class;
            try {
                jar_class = Class.forName("java.net.JarURLConnection");
            } catch (Exception e2) {
                return null;
            }
            Object jar;
            try {
                jar = url.openConnection();
            } catch (IOException e2) {
                return null;
            }
            if (jar == null) {
                return null;
            }
            try {
                Method m = jar_class.getMethod("openConnection", ((java.lang.Class[]) null));
                content = m.invoke(jar, ((java.lang.Object[]) null));
            } catch (Exception e2) {
                return null;
            }
        } catch (IOException e) {
            return null;
        } catch (SecurityException e) {
            return null;
        }
        if (content instanceof String) {
            return (String) content;
        } else if (content instanceof InputStream) {
            InputStream fs = (InputStream) content;
            try {
                byte charArray[] = new byte[fs.available()];
                fs.read(charArray);
                return new String(charArray);
            } catch (IOException e2) {
                return null;
            } finally {
                closeInputStream(fs);
            }
        } else {
            return null;
        }
    }
protected static void clearTables() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = FidoDataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            ClearData.clearTables(stmt);
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (2, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (3, '')");
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        }
    }
private String getXML(String url) throws ClientProtocolException, IOException {
        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(url);
        HttpResponse responseGet = client.execute(get);
        HttpEntity resEntityGet = responseGet.getEntity();
        BufferedReader in = new BufferedReader(new InputStreamReader(resEntityGet.getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();
        String xml = sb.toString();
        return xml;
    }
protected static boolean isLatestVersion(double myVersion, String referenceAddress) {
        Scanner scanner = null;
        try {
            URL url = new URL(referenceAddress);
            InputStream iS = url.openStream();
            scanner = new Scanner(iS);
            String firstLine = scanner.nextLine();
            double latestVersion = Double.valueOf(firstLine.trim());
            return myVersion >= latestVersion;
        } catch (Exception e) {
            displaySimpleAlert(null, "Cannot check latest version...check internet connection?");
            return false;
        }
    }
private static File[] getWsdls(File dirfile) throws Exception {
        File[] allfiles = dirfile.listFiles();
        List<File> files = new ArrayList<File>();
        if (allfiles != null) {
            MessageDigest md = MessageDigest.getInstance("MD5");
            String outputDir = argMap.get(OUTPUT_DIR);
            for (File file : allfiles) {
                if (file.getName().endsWith(WSDL_SUFFIX)) {
                    files.add(file);
                }
                if (file.getName().endsWith(WSDL_SUFFIX) || file.getName().endsWith(XSD_SUFFIX)) {
                    md.update(FileUtil.getBytes(file));
                }
            }
            computedHash = md.digest();
            hashFile = new File(outputDir + File.separator + argMap.get(BASE_PACKAGE).replace('.', File.separatorChar) + File.separator + "hash.md5");
            if (hashFile.exists()) {
                byte[] readHash = FileUtil.getBytes(hashFile);
                if (Arrays.equals(readHash, computedHash)) {
                    System.out.println("Skipping generation, files not changed.");
                    files.clear();
                }
            }
        }
        File[] filesarr = new File[files.size()];
        files.toArray(filesarr);
        return filesarr;
    }
public static String CheckUrl(String urlvalue) {
        String inputLine = "";
        try {
            URL url = new URL(urlvalue);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            inputLine = in.readLine().toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return inputLine;
    }
private void getPicture(String urlPath, String picId) throws Exception {
        URL url = new URL(urlPath);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(10000);
        if (conn.getResponseCode() == 200) {
            InputStream inputStream = conn.getInputStream();
            byte[] data = readStream(inputStream);
            File file = new File(picDirectory + picId);
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(data);
            outputStream.close();
        }
        conn.disconnect();
    }
public String obfuscateString(String string) {
        String obfuscatedString = null;
        try {
            MessageDigest md = MessageDigest.getInstance(ENCRYPTION_ALGORITHM);
            md.update(string.getBytes());
            byte[] digest = md.digest();
            obfuscatedString = new String(Base64.encode(digest)).replace(DELIM_PATH, '=');
        } catch (NoSuchAlgorithmException e) {
            StatusHandler.log("SHA not available", null);
            obfuscatedString = LABEL_FAILED_TO_OBFUSCATE;
        }
        return obfuscatedString;
    }