semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String generateGuid(boolean secure) {
        MessageDigest md5 = null;
        String valueBeforeMD5 = null;
        String valueAfterMD5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0L;
            if (secure) rand = mySecureRand.nextLong(); else rand = myRand.nextLong();
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte array[] = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; j++) {
                int b = array[j] & 0xff;
                if (b < 16) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
        String raw = valueAfterMD5.toUpperCase();
        StringBuffer sb = new StringBuffer();
        sb.append(raw.substring(0, 8));
        sb.append("-");
        sb.append(raw.substring(8, 12));
        sb.append("-");
        sb.append(raw.substring(12, 16));
        sb.append("-");
        sb.append(raw.substring(16, 20));
        sb.append("-");
        sb.append(raw.substring(20));
        return sb.toString();
    }
public static void copyFromTo(String src, String des) {
        staticprintln("Copying:\"" + src + "\"\nto:\"" + des + "\"");
        try {
            FileChannel srcChannel = new FileInputStream(src).getChannel();
            FileChannel dstChannel = new FileOutputStream(des).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException e) {
        }
    }
@Override
    public void doHandler(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        if (request.getRequestURI().indexOf(".swf") != -1) {
            String fullUrl = (String) request.getAttribute("fullUrl");
            fullUrl = urlTools.urlFilter(fullUrl, true);
            response.setCharacterEncoding("gbk");
            response.setContentType("application/x-shockwave-flash");
            PrintWriter out = response.getWriter();
            try {
                URL url = new URL(fullUrl);
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "gbk"));
                fileEditor.pushStream(out, in, null, true);
            } catch (Exception e) {
            }
            out.flush();
        } else if (request.getRequestURI().indexOf(".xml") != -1) {
            response.setContentType("text/xml");
            PrintWriter out = response.getWriter();
            try {
                URL url = new URL("http://" + configCenter.getUcoolOnlineIp() + request.getRequestURI());
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                fileEditor.pushStream(out, in, null, true);
            } catch (Exception e) {
            }
            out.flush();
        }
    }
public static BufferedReader openForReading(String name, URI base, ClassLoader classLoader) throws IOException {
        if ((name == null) || name.trim().equals("")) {
            return null;
        }
        if (name.trim().equals("System.in")) {
            if (STD_IN == null) {
                STD_IN = new BufferedReader(new InputStreamReader(System.in));
            }
            return STD_IN;
        }
        URL url = nameToURL(name, base, classLoader);
        if (url == null) {
            throw new IOException("Could not convert \"" + name + "\" with base \"" + base + "\" to a URL.");
        }
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(url.openStream());
        } catch (IOException ex) {
            try {
                URL possibleJarURL = ClassUtilities.jarURLEntryResource(url.toString());
                if (possibleJarURL != null) {
                    inputStreamReader = new InputStreamReader(possibleJarURL.openStream());
                }
                return new BufferedReader(inputStreamReader);
            } catch (Exception ex2) {
                try {
                    if (inputStreamReader != null) {
                        inputStreamReader.close();
                    }
                } catch (IOException ex3) {
                }
                IOException ioException = new IOException("Failed to open \"" + url + "\".");
                ioException.initCause(ex);
                throw ioException;
            }
        }
        return new BufferedReader(inputStreamReader);
    }
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException {
        if (TDebug.TraceAudioFileReader) {
            TDebug.out("MpegAudioFileReader.getAudioInputStream(URL): begin");
        }
        long lFileLengthInBytes = AudioSystem.NOT_SPECIFIED;
        URLConnection conn = url.openConnection();
        boolean isShout = false;
        int toRead = 4;
        byte[] head = new byte[toRead];
        conn.setRequestProperty("Icy-Metadata", "1");
        BufferedInputStream bInputStream = new BufferedInputStream(conn.getInputStream());
        bInputStream.mark(toRead);
        int read = bInputStream.read(head, 0, toRead);
        if ((read > 2) && (((head[0] == 'I') | (head[0] == 'i')) && ((head[1] == 'C') | (head[1] == 'c')) && ((head[2] == 'Y') | (head[2] == 'y')))) isShout = true;
        bInputStream.reset();
        InputStream inputStream = null;
        if (isShout == true) {
            IcyInputStream icyStream = new IcyInputStream(bInputStream);
            icyStream.addTagParseListener(IcyListener.getInstance());
            inputStream = icyStream;
        } else {
            String metaint = conn.getHeaderField("icy-metaint");
            if (metaint != null) {
                IcyInputStream icyStream = new IcyInputStream(bInputStream, metaint);
                icyStream.addTagParseListener(IcyListener.getInstance());
                inputStream = icyStream;
            } else {
                inputStream = bInputStream;
            }
        }
        AudioInputStream audioInputStream = null;
        try {
            audioInputStream = getAudioInputStream(inputStream, lFileLengthInBytes);
        } catch (UnsupportedAudioFileException e) {
            inputStream.close();
            throw e;
        } catch (IOException e) {
            inputStream.close();
            throw e;
        }
        if (TDebug.TraceAudioFileReader) {
            TDebug.out("MpegAudioFileReader.getAudioInputStream(URL): end");
        }
        return audioInputStream;
    }
public File mergeDoc(URL urlDoc, File fOutput, boolean bMulti) throws Exception {
        if (s_log.isTraceEnabled()) trace(0, "Copying from " + urlDoc.toString() + " to " + fOutput.toString());
        File fOut = null;
        InputStream is = null;
        try {
            is = urlDoc.openStream();
            fOut = mergeDoc(is, fOutput, bMulti);
        } finally {
            is.close();
        }
        return fOut;
    }
private BibtexDatabase importInspireEntries(String key, OutputPrinter frame) {
        String url = constructUrl(key);
        try {
            HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
            conn.setRequestProperty("User-Agent", "Jabref");
            InputStream inputStream = conn.getInputStream();
            INSPIREBibtexFilterReader reader = new INSPIREBibtexFilterReader(new InputStreamReader(inputStream));
            ParserResult pr = BibtexParser.parse(reader);
            return pr.getDatabase();
        } catch (IOException e) {
            frame.showMessage(Globals.lang("An Exception ocurred while accessing '%0'", url) + "\n\n" + e.toString(), Globals.lang(getKeyName()), JOptionPane.ERROR_MESSAGE);
        } catch (RuntimeException e) {
            frame.showMessage(Globals.lang("An Error occurred while fetching from INSPIRE source (%0):", new String[] { url }) + "\n\n" + e.getMessage(), Globals.lang(getKeyName()), JOptionPane.ERROR_MESSAGE);
        }
        return null;
    }
private String getImageUrlForComicsJoke(Date date, String baseURL, String imageDefinition, int imagePathStart) throws JokeFinderException {
        String imageUrl = null;
        try {
            imageUrl = getBaseImageComicsJoke(date, baseURL, imageDefinition, imagePathStart);
            URL url = new URL(imageUrl);
            url.openStream();
        } catch (JokeFinderException e) {
            logger.warn("Couldn't find base URL.", e);
            imageUrl = null;
        } catch (IOException e) {
            logger.warn("Couldn't find or open image base URL.", e);
            imageUrl = null;
        }
        if (imageUrl == null) {
            throw new JokeFinderException("Couldn't find joke.");
        }
        return imageUrl;
    }
@SuppressWarnings({ "ResultOfMethodCallIgnored" })
    public static Node combineCss(URL base, List<Node> linkCss, List<File> newFiles) throws IOException {
        File dir = File.createTempFile("css", "" + System.currentTimeMillis());
        StringBuilder name = new StringBuilder();
        try {
            if (dir.delete() && dir.mkdirs()) {
                File minDir = new File(dir, "min");
                minDir.mkdir();
                File combineFile = new File(minDir, "style.css");
                Writer writer = new FileWriter(combineFile);
                boolean first = true;
                for (Node link : linkCss) {
                    String path = ((Element) link).getAttribute("href");
                    URL url = new URL(buildUrl(base, path));
                    InputStream inputStream = url.openStream();
                    File cssFile = new File(dir, fileName(url));
                    FileOutputStream outputStream = new FileOutputStream(cssFile);
                    IOUtils.copy(inputStream, outputStream);
                    outputStream.close();
                    inputStream.close();
                    if (!first) {
                        writer.write('\n');
                    } else {
                        first = false;
                    }
                    Reader reader = new FileReader(cssFile);
                    if (Configuration.cssMinification()) {
                        CssCompressor cssCompressor = new CssCompressor(reader);
                        cssCompressor.compress(writer, 0);
                    } else {
                        IOUtils.copy(reader, writer);
                    }
                    reader.close();
                    String fileName = cssFile.getName();
                    int pos = fileName.lastIndexOf('.');
                    if (pos >= 0) {
                        fileName = fileName.substring(0, pos);
                    }
                    name.append(fileName).append(",");
                }
                writer.close();
                FileReader reader = new FileReader(combineFile);
                name.append(hashCode(IOUtils.toString(reader))).append(".css");
                reader.close();
                File targetFile = new File(Configuration.getCssLocalDir(), name.toString());
                if (!targetFile.exists()) {
                    targetFile.getParentFile().mkdirs();
                    FileUtils.copyFile(combineFile, targetFile);
                    newFiles.add(targetFile);
                    logger.info("Combined several css files into the single " + targetFile + " [size=" + targetFile.length() + "].");
                }
            }
        } finally {
            FileUtils.deleteQuietly(dir);
        }
        if (name.length() != 0) {
            Element element = (Element) linkCss.get(0);
            element.setAttribute("href", Configuration.getCssUrlPrefix() + name.toString());
            return element;
        } else {
            return null;
        }
    }
public static void bubbleSort(int[] a) {
        for (int i = a.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[j + 1]) {
                    int tmp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = tmp;
                }
            }
        }
    }
public byte[] encryptMsg(String encryptString) {
        byte[] encryptByte = null;
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(encryptString.getBytes());
            encryptByte = messageDigest.digest();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return encryptByte;
    }
private NodeInfo loadNodeMeta(int id, int properties) {
        String query = mServer + "load.php" + ("?id=" + id) + ("&mask=" + properties);
        NodeInfo info = null;
        try {
            URL url = new URL(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setAllowUserInteraction(false);
            conn.setRequestMethod("GET");
            setCredentials(conn);
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream stream = conn.getInputStream();
                MimeType contentType = new MimeType(conn.getContentType());
                if (contentType.getBaseType().equals("text/xml")) {
                    try {
                        JAXBContext context = JAXBContext.newInstance(NetProcessorInfo.class);
                        Unmarshaller unm = context.createUnmarshaller();
                        NetProcessorInfo root = (NetProcessorInfo) unm.unmarshal(stream);
                        if ((root != null) && (root.getNodes().length == 1)) {
                            info = root.getNodes()[0];
                        }
                    } catch (Exception ex) {
                    }
                }
                stream.close();
            }
        } catch (Exception ex) {
        }
        return info;
    }
private boolean loadNodeData(NodeInfo info) {
        String query = mServer + "load.php" + ("?id=" + info.getId()) + ("&mask=" + NodePropertyFlag.Data);
        boolean rCode = false;
        try {
            URL url = new URL(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setAllowUserInteraction(false);
            conn.setRequestMethod("GET");
            setCredentials(conn);
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream stream = conn.getInputStream();
                byte[] data = new byte[0], temp = new byte[1024];
                boolean eof = false;
                while (!eof) {
                    int read = stream.read(temp);
                    if (read > 0) {
                        byte[] buf = new byte[data.length + read];
                        System.arraycopy(data, 0, buf, 0, data.length);
                        System.arraycopy(temp, 0, buf, data.length, read);
                        data = buf;
                    } else if (read < 0) {
                        eof = true;
                    }
                }
                info.setData(data);
                info.setMIMEType(new MimeType(conn.getContentType()));
                rCode = true;
                stream.close();
            }
        } catch (Exception ex) {
        }
        return rCode;
    }
private boolean saveNodeMeta(NodeInfo info, int properties) {
        boolean rCode = false;
        String query = mServer + "save.php" + ("?id=" + info.getId());
        try {
            URL url = new URL(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            byte[] body = Helpers.EncodeString(Helpers.ASCII, createURLEncodedPropertyString(info, properties));
            conn.setAllowUserInteraction(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            setCredentials(conn);
            conn.setDoOutput(true);
            conn.getOutputStream().write(body);
            rCode = saveNode(info, conn);
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.toString());
        }
        return rCode;
    }
private boolean saveNodeData(NodeInfo info) {
        boolean rCode = false;
        String query = mServer + "save.php" + ("?id=" + info.getId());
        try {
            URL url = new URL(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String contentType = info.getMIMEType().toString();
            byte[] body = info.getData();
            conn.setAllowUserInteraction(false);
            conn.setRequestMethod("PUT");
            if (contentType.equals("")) {
                contentType = "application/octet-stream";
            }
            System.out.println("contentType: " + contentType);
            conn.setRequestProperty("Content-Type", contentType);
            setCredentials(conn);
            conn.setDoOutput(true);
            conn.getOutputStream().write(body);
            rCode = saveNode(info, conn);
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.toString());
        }
        return rCode;
    }
public static int save(byte[] bytes, File outputFile) throws IOException {
        InputStream in = new ByteArrayInputStream(bytes);
        outputFile.getParentFile().mkdirs();
        OutputStream out = new FileOutputStream(outputFile);
        try {
            return IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
            try {
                out.close();
            } catch (IOException ioe) {
                ioe.getMessage();
            }
            try {
                in.close();
            } catch (IOException ioe) {
                ioe.getMessage();
            }
        }
    }
public static int save(File inputFile, File outputFile) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(inputFile);
            outputFile.getParentFile().mkdirs();
            out = new FileOutputStream(outputFile);
        } catch (Exception e) {
            e.getMessage();
        }
        try {
            return IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
                ioe.getMessage();
            }
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ioe) {
                ioe.getMessage();
            }
        }
    }
public static List<String> extract(String zipFilePath, String destDirPath) throws IOException {
        List<String> list = null;
        ZipFile zip = new ZipFile(zipFilePath);
        try {
            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                File destFile = new File(destDirPath, entry.getName());
                if (entry.isDirectory()) {
                    destFile.mkdirs();
                } else {
                    InputStream in = zip.getInputStream(entry);
                    OutputStream out = new FileOutputStream(destFile);
                    try {
                        IOUtils.copy(in, out);
                    } finally {
                        IOUtils.closeQuietly(in);
                        IOUtils.closeQuietly(out);
                        try {
                            out.close();
                        } catch (IOException ioe) {
                            ioe.getMessage();
                        }
                        try {
                            in.close();
                        } catch (IOException ioe) {
                            ioe.getMessage();
                        }
                    }
                }
                if (list == null) {
                    list = new ArrayList<String>();
                }
                list.add(destFile.getAbsolutePath());
            }
            return list;
        } finally {
            try {
                zip.close();
            } catch (Exception e) {
                e.getMessage();
            }
        }
    }
public static String uncompress(String readPath, boolean mkdir) throws Exception {
        ZipArchiveInputStream arcInputStream = new ZipArchiveInputStream(new FileInputStream(readPath));
        BufferedInputStream bis = new BufferedInputStream(arcInputStream);
        File baseDir = new File(readPath).getParentFile();
        String basePath = baseDir.getPath() + "/";
        if (mkdir) {
            String[] schema = readPath.split("/");
            String baseName = schema[schema.length - 1].replaceAll(".zip", "");
            FileUtils.forceMkdir(new File(basePath + baseName));
            basePath = basePath + baseName + "/";
        }
        ArchiveEntry entry;
        while ((entry = arcInputStream.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                FileUtils.forceMkdir(new File(basePath + entry.getName()));
            } else {
                String writePath = basePath + entry.getName();
                String dirName = FilenameUtils.getPath(writePath);
                FileUtils.forceMkdir(new File(dirName));
                BufferedOutputStream bos = new BufferedOutputStream(FileUtils.openOutputStream(new File(writePath)));
                int i = 0;
                while ((i = bis.read()) != -1) {
                    bos.write(i);
                }
                IOUtils.closeQuietly(bos);
            }
        }
        IOUtils.closeQuietly(bis);
        return basePath;
    }
public void actionPerformed(ActionEvent e) {
        JFileChooser fc = new JFileChooser("");
        fc.setMultiSelectionEnabled(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int option = 0;
        boolean save = m_data != null;
        if (save) option = fc.showSaveDialog(this); else option = fc.showOpenDialog(this);
        if (option != JFileChooser.APPROVE_OPTION) return;
        File file = fc.getSelectedFile();
        if (file == null) return;
        log.info(file.toString());
        try {
            if (save) {
                FileOutputStream os = new FileOutputStream(file);
                byte[] buffer = (byte[]) m_data;
                os.write(buffer);
                os.flush();
                os.close();
                log.config("Save to " + file + " #" + buffer.length);
            } else {
                FileInputStream is = new FileInputStream(file);
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024 * 8];
                int length = -1;
                while ((length = is.read(buffer)) != -1) os.write(buffer, 0, length);
                is.close();
                byte[] data = os.toByteArray();
                m_data = data;
                log.config("Load from " + file + " #" + data.length);
                os.close();
            }
        } catch (Exception ex) {
            log.log(Level.WARNING, "Save=" + save, ex);
        }
        try {
            fireVetoableChange(m_columnName, null, m_data);
        } catch (PropertyVetoException pve) {
        }
    }