semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void execute(File sourceFile, File destinationFile, String conversionType, Properties java2HtmlConfig) {
        FileReader reader = null;
        Writer writer = null;
        try {
            reader = new FileReader(sourceFile);
            logger.info("Using source file: " + trimPath(userDir, sourceFile));
            if (!destinationFile.getParentFile().exists()) {
                createDirectory(destinationFile.getParentFile());
            }
            writer = new FileWriter(destinationFile);
            logger.info("Destination file:  " + trimPath(userDir, destinationFile));
            execute(reader, writer, conversionType, java2HtmlConfig);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                    writer = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (reader != null) {
                try {
                    reader.close();
                    reader = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
void bsort(int a[], int lo, int hi) throws Exception {
        for (int j = hi; j > lo; j--) {
            for (int i = lo; i < j; i++) {
                if (a[i] > a[i + 1]) {
                    int T = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = T;
                    pause();
                }
            }
        }
    }
public void testRenderRules() {
        try {
            MappingManager manager = new MappingManager();
            OWLOntologyManager omanager = OWLManager.createOWLOntologyManager();
            OWLOntology srcOntology;
            OWLOntology targetOntology;
            manager.loadMapping(rulesDoc.toURL());
            srcOntology = omanager.loadOntologyFromPhysicalURI(srcURI);
            targetOntology = omanager.loadOntologyFromPhysicalURI(targetURI);
            manager.setSourceOntology(srcOntology);
            manager.setTargetOntology(targetOntology);
            Graph srcGraph = manager.getSourceGraph();
            Graph targetGraph = manager.getTargetGraph();
            System.out.println("Starting to render...");
            FlexGraphViewFactory factory = new FlexGraphViewFactory();
            factory.setColorScheme(ColorSchemes.BLUES);
            factory.visit(srcGraph);
            GraphView view = factory.getGraphView();
            GraphViewRenderer renderer = new FlexGraphViewRenderer();
            renderer.setGraphView(view);
            System.out.println("View updated with graph...");
            InputStream xmlStream = renderer.renderGraphView();
            StringWriter writer = new StringWriter();
            IOUtils.copy(xmlStream, writer);
            System.out.println("Finished writing");
            writer.close();
            System.out.println("Finished render... XML is:");
            System.out.println(writer.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }
    }
private void initURL() {
        try {
            log.fine("Checking: " + locator);
            URLConnection conn = URIFactory.url(locator).openConnection();
            conn.setUseCaches(false);
            log.info(conn.getHeaderFields().toString());
            String header = conn.getHeaderField(null);
            if (header.contains("404")) {
                log.info("404 file not found: " + locator);
                return;
            }
            if (header.contains("500")) {
                log.info("500 server error: " + locator);
                return;
            }
            if (conn.getContentLength() > 0) {
                byte[] buffer = new byte[50];
                conn.getInputStream().read(buffer);
                if (new String(buffer).trim().startsWith("<!DOCTYPE")) return;
            } else if (conn.getContentLength() == 0) {
                exists = true;
                return;
            }
            exists = true;
            length = conn.getContentLength();
        } catch (Exception ioe) {
            System.err.println(ioe);
        }
    }
public void putMedia(Media m) {
        if (m == null) {
            return;
        }
        if (_conn == null) {
            log.error("DatabaseDatastore not connected!");
            return;
        }
        if (log.isTraceEnabled()) {
            log.trace("Writing Media " + m.toString() + " to database");
        }
        try {
            try {
                long trackid = getLocalID(m, _conn);
                if (m.isBaseDirty()) {
                    if (log.isTraceEnabled()) {
                        log.trace("Need to update base " + m.getID() + " to database");
                    }
                    Integer artist = getArtistID(m, _conn);
                    Integer author = getAuthorID(m, _conn);
                    Integer artistAlias = getArtistAliasID(m, _conn);
                    PreparedStatement s = _conn.prepareStatement("update media_track set track_name=?,track_artist_id=?,track_author_id=?,track_artist_alias_id=?,track_audit_timestamp=CURRENT_TIMESTAMP where track_id = ?");
                    s.setString(1, m.getName());
                    if (artist != null) {
                        s.setLong(2, artist);
                    } else {
                        s.setNull(2, Types.BIGINT);
                    }
                    if (author != null) {
                        s.setLong(3, author);
                    } else {
                        s.setNull(3, Types.BIGINT);
                    }
                    if (artistAlias != null) {
                        s.setLong(4, artistAlias);
                    } else {
                        s.setNull(4, Types.BIGINT);
                    }
                    s.setLong(5, trackid);
                    s.executeUpdate();
                    s.close();
                }
                if (m.isUserDirty()) {
                    if (log.isTraceEnabled()) {
                        log.trace("Need to update user " + m.getID() + " to database");
                    }
                    PreparedStatement s = _conn.prepareStatement("update media_track_rating set rating=?, play_count=? where track_id=? and user_id=?");
                    s.setFloat(1, m.getRating());
                    s.setLong(2, m.getPlayCount());
                    s.setLong(3, trackid);
                    s.setLong(4, userid);
                    if (s.executeUpdate() != 1) {
                        s.close();
                    }
                    s.close();
                }
                if (m.isContentDirty()) {
                    updateLocation(m, _conn);
                }
                _conn.commit();
                m.resetDirty();
                if (log.isTraceEnabled()) {
                    log.trace("Committed " + m.getID() + " to database");
                }
            } catch (Exception e) {
                log.error(e.toString(), e);
                _conn.rollback();
            }
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
    }
public void merge(VMImage image, VMSnapShot another) throws VMException {
        if (path == null || another.getPath() == null) throw new VMException("EmuVMSnapShot is NULL!");
        logging.debug(LOG_NAME, "merge images  " + path + " and " + another.getPath());
        File target = new File(path);
        File src = new File(another.getPath());
        if (target.isDirectory() || src.isDirectory()) return;
        try {
            FileInputStream in = new FileInputStream(another.getPath());
            FileChannel inChannel = in.getChannel();
            FileOutputStream out = new FileOutputStream(path, true);
            FileChannel outChannel = out.getChannel();
            outChannel.transferFrom(inChannel, 0, inChannel.size());
            outChannel.close();
            inChannel.close();
        } catch (IOException e) {
            throw new VMException(e);
        }
    }
private void setup() {
        env = new EnvAdvanced();
        try {
            URL url = Sysutil.getURL("world.env");
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split(",");
                if (fields[0].equalsIgnoreCase("skybox")) {
                    env.setRoom(new EnvSkyRoom(fields[1]));
                } else if (fields[0].equalsIgnoreCase("camera")) {
                    env.setCameraXYZ(Double.parseDouble(fields[1]), Double.parseDouble(fields[2]), Double.parseDouble(fields[3]));
                    env.setCameraYaw(Double.parseDouble(fields[4]));
                    env.setCameraPitch(Double.parseDouble(fields[5]));
                } else if (fields[0].equalsIgnoreCase("terrain")) {
                    terrain = new EnvTerrain(fields[1]);
                    terrain.setTexture(fields[2]);
                    env.addObject(terrain);
                } else if (fields[0].equalsIgnoreCase("object")) {
                    GameObject n = (GameObject) Class.forName(fields[10]).newInstance();
                    n.setX(Double.parseDouble(fields[1]));
                    n.setY(Double.parseDouble(fields[2]));
                    n.setZ(Double.parseDouble(fields[3]));
                    n.setScale(Double.parseDouble(fields[4]));
                    n.setRotateX(Double.parseDouble(fields[5]));
                    n.setRotateY(Double.parseDouble(fields[6]));
                    n.setRotateZ(Double.parseDouble(fields[7]));
                    n.setTexture(fields[9]);
                    n.setModel(fields[8]);
                    n.setEnv(env);
                    env.addObject(n);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public String hash(String clearPassword) {
        if (osalt == 0) return null;
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new AssertionError("Can't find the SHA1 algorithm in the java.security package");
        }
        String saltString = String.valueOf(osalt);
        md.update(saltString.getBytes());
        md.update(clearPassword.getBytes());
        byte[] digestBytes = md.digest();
        StringBuffer digestSB = new StringBuffer();
        for (int i = 0; i < digestBytes.length; i++) {
            int lowNibble = digestBytes[i] & 0x0f;
            int highNibble = (digestBytes[i] >> 4) & 0x0f;
            digestSB.append(Integer.toHexString(highNibble));
            digestSB.append(Integer.toHexString(lowNibble));
        }
        String digestStr = digestSB.toString();
        return digestStr;
    }
public void init(IWorkbench workbench) {
        preferences.setFilename(CorePlugin.getDefault().getStateLocation().append("log4j.properties").toOSString());
        registry = Platform.getExtensionRegistry();
        extensionPoint = registry.getExtensionPoint(CorePlugin.LOGGER_PREFERENCES_EXTENSION_POINT);
        IConfigurationElement[] members = extensionPoint.getConfigurationElements();
        for (int i = 0; i < members.length; i++) {
            IConfigurationElement element = members[i];
            if (element.getName().equals("logger")) {
                if (element.getAttribute("defaultValue") != null) {
                    String[] item = element.getAttribute("name").split(";");
                    for (int x = 0; x < item.length; x++) preferences.setDefault("log4j.logger." + item[x], element.getAttribute("defaultValue"));
                }
            }
        }
        try {
            URL url = CorePlugin.getDefault().getBundle().getResource("log4j.properties");
            Properties properties = new Properties();
            properties.load(url.openStream());
            for (Iterator iter = properties.keySet().iterator(); iter.hasNext(); ) {
                String key = (String) iter.next();
                preferences.setDefault(key, (String) properties.get(key));
            }
            File file = CorePlugin.getDefault().getStateLocation().append("log4j.properties").toFile();
            if (file.exists()) preferences.load(new FileInputStream(file));
        } catch (Exception e) {
            CorePlugin.logException(e);
        }
    }
@Override
    public String getData(String blipApiPath, String authHeader) {
        try {
            URL url = new URL(BLIP_API_URL + blipApiPath);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            if (authHeader != null) {
                conn.addRequestProperty("Authorization", "Basic " + authHeader);
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            StringBuffer content = new StringBuffer();
            System.out.println("Resp code " + conn.getResponseCode());
            while ((line = reader.readLine()) != null) {
                System.out.println(">> " + line);
                content.append(line);
            }
            reader.close();
            return content.toString();
        } catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
public List execute(ComClient comClient) throws Exception {
        ArrayList outStrings = new ArrayList();
        SearchResult sr = Util.getSearchResultByIDAndNum(SearchManager.getInstance(), qID, dwNum);
        for (int i = 0; i < checkerUrls.length; i++) {
            String parametrizedURL = checkerUrls[i];
            Iterator mtIter = sr.iterateMetatags();
            while (mtIter.hasNext()) {
                Map.Entry mt = (Map.Entry) mtIter.next();
                parametrizedURL = parametrizedURL.replaceAll("%%" + mt.getKey() + "%%", mt.getValue().toString());
                if (mt.getKey().equals("fake") && ((Boolean) mt.getValue()).booleanValue()) {
                    outStrings.add("it's a fake.");
                    return outStrings;
                }
            }
            parametrizedURL = parametrizedURL.replaceAll("%%fileid%%", sr.getFileHash().toString());
            System.out.println("parametrizedURL=" + parametrizedURL);
            try {
                URL url = new URL(parametrizedURL);
                URLConnection connection = url.openConnection();
                connection.connect();
                BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String str = null;
                while ((str = br.readLine()) != null) {
                    System.out.println(str);
                    if (str.indexOf(fakeMarks[i]) != -1) {
                        System.out.println("FAKEFAKEFAKE");
                        sr.addMetatag("fake", Boolean.TRUE);
                        outStrings.add("it's a fake.");
                        break;
                    }
                }
            } catch (MalformedURLException murl_err) {
                murl_err.printStackTrace();
            } catch (IOException io_err) {
                io_err.printStackTrace();
            } catch (Exception err) {
                err.printStackTrace();
            }
        }
        return outStrings;
    }
public static String translate(String s) {
        try {
            String result = null;
            URL url = new URL("http://translate.google.com/translate_t");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
            connection.setDoOutput(true);
            PrintWriter out = new PrintWriter(connection.getOutputStream());
            out.print("text=" + URLEncoder.encode(s, "UTF-8") + "&langpair=");
            if (s.matches("[\\u0000-\\u00ff]+")) {
                out.print("en|ja");
            } else {
                out.print("ja|en");
            }
            out.print("&hl=en&ie=UTF-8&oe=UTF-8");
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                int textPos = inputLine.indexOf("id=result_box");
                if (textPos >= 0) {
                    int ltrPos = inputLine.indexOf("dir=ltr", textPos + 9);
                    if (ltrPos >= 0) {
                        int closePos = inputLine.indexOf("<", ltrPos + 8);
                        if (closePos >= 0) {
                            result = inputLine.substring(ltrPos + 8, closePos);
                        }
                    }
                }
            }
            in.close();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public static void main(String args[]) {
        if (args.length < 1) {
            System.err.println("usage: java copyURL URL [LocalFile]");
            System.exit(1);
        }
        try {
            URL url = new URL(args[0]);
            System.out.println("Opening connection to " + args[0] + "...");
            URLConnection urlC = url.openConnection();
            InputStream is = url.openStream();
            System.out.print("Copying resource (type: " + urlC.getContentType());
            Date date = new Date(urlC.getLastModified());
            System.out.flush();
            FileOutputStream fos = null;
            if (args.length < 2) {
                String localFile = null;
                StringTokenizer st = new StringTokenizer(url.getFile(), "/");
                while (st.hasMoreTokens()) localFile = st.nextToken();
                fos = new FileOutputStream(localFile);
            } else fos = new FileOutputStream(args[1]);
            int oneChar, count = 0;
            while ((oneChar = is.read()) != -1) {
                fos.write(oneChar);
                count++;
            }
            is.close();
            fos.close();
            System.out.println(count + " byte(s) copied");
        } catch (MalformedURLException e) {
            System.err.println(e.toString());
        } catch (IOException e) {
            System.err.println(e.toString());
        }
    }
public void copyFile(String source, String destination, String description, boolean recursive) throws Exception {
        File sourceFile = new File(source);
        File destinationFile = new File(destination);
        if (!sourceFile.exists()) {
            throw new Exception("source file (" + source + ") does not exist!");
        }
        if (!sourceFile.isFile()) {
            throw new Exception("source file (" + source + ") is not a file!");
        }
        if (!sourceFile.canRead()) {
            throw new Exception("source file (" + source + ") is not readable!");
        }
        if (destinationFile.exists()) {
            m_out.print("  - " + destination + " exists, removing... ");
            if (destinationFile.delete()) {
                m_out.println("REMOVED");
            } else {
                m_out.println("FAILED");
                throw new Exception("unable to delete existing file: " + sourceFile);
            }
        }
        m_out.print("  - copying " + source + " to " + destination + "... ");
        if (!destinationFile.getParentFile().exists()) {
            if (!destinationFile.getParentFile().mkdirs()) {
                throw new Exception("unable to create directory: " + destinationFile.getParent());
            }
        }
        if (!destinationFile.createNewFile()) {
            throw new Exception("unable to create file: " + destinationFile);
        }
        FileChannel from = null;
        FileChannel to = null;
        try {
            from = new FileInputStream(sourceFile).getChannel();
            to = new FileOutputStream(destinationFile).getChannel();
            to.transferFrom(from, 0, from.size());
        } catch (FileNotFoundException e) {
            throw new Exception("unable to copy " + sourceFile + " to " + destinationFile, e);
        } finally {
            if (from != null) {
                from.close();
            }
            if (to != null) {
                to.close();
            }
        }
        m_out.println("DONE");
    }
public static void readUrlWriteFileTest(String url, String fileName) throws Exception {
        System.out.println("Initiated reading source queue URL: " + url);
        InputStream instream = new URL(url).openStream();
        Serializer serializer = new Serializer();
        Response response = (Response) serializer.parse(instream);
        Queue queue = response.getQueue();
        instream.close();
        System.out.println("Completed reading source queue URL (jobs=" + queue.size() + ")");
        System.out.println("Initiated writing target queue File: " + fileName);
        OutputStream outstream = new FileOutputStream(fileName);
        serializer.write(response, outstream);
        outstream.close();
        System.out.println("Completed writing target queue file.");
    }
public void buildDocument(Files page) {
        String uri = constructFileUrlString(page, true);
        URL url;
        try {
            url = new URL(uri);
            URLConnection connection = url.openConnection();
            InputStream in = connection.getInputStream();
            Reader reader = new InputStreamReader(in, "UTF8");
            xsltInputSource = new InputSourceImpl(reader, uri);
            xsltInputSource.setEncoding("utf-8");
            UserAgentContext ucontext = new CobraConfig.LocalUserAgentContext();
            HtmlRendererContext rendererContext = new CobraConfig.LocalHtmlRendererContext(htmlPanel, ucontext);
            DocumentBuilderImpl builder = new DocumentBuilderImpl(rendererContext.getUserAgentContext(), rendererContext);
            xsltDocument = builder.parse(xsltInputSource);
            htmlPanel.setDocument(xsltDocument, rendererContext);
            documentHolder = xsltDocument.toString();
            in.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
    }
public static String digest(String value, String algorithm) throws Exception {
        MessageDigest algo = MessageDigest.getInstance(algorithm);
        algo.reset();
        algo.update(value.getBytes("UTF-8"));
        return StringTool.byteArrayToString(algo.digest());
    }
public static String encryptPassword(String password) throws PasswordException {
        String hash = null;
        if (password != null && !password.equals("")) {
            try {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(password.getBytes("UTF-8"));
                byte raw[] = md.digest();
                hash = String.valueOf(Base64Coder.encode(raw));
            } catch (NoSuchAlgorithmException nsae) {
                throw new PasswordException(PasswordException.SYSTEM_ERROR);
            } catch (UnsupportedEncodingException uee) {
                throw new PasswordException(PasswordException.SYSTEM_ERROR);
            }
        }
        return hash;
    }
public TempFileBinaryBody(InputStream is) throws IOException {
        TempPath tempPath = TempStorage.getInstance().getRootTempPath();
        tempFile = tempPath.createTempFile("attachment", ".bin");
        OutputStream out = tempFile.getOutputStream();
        IOUtils.copy(is, out);
        out.close();
    }