semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void performDownload() {
        List<String> selected = filesPane.getSelectedValuesList();
        if (selected == null || selected.isEmpty() || selected.size() != 1) {
            JOptionPane.showMessageDialog(this, "Please select one path");
            return;
        }
        RFile file = new RFile(selected.get(0));
        if (!file.isFile()) {
            JOptionPane.showMessageDialog(this, "file does not exist anymore");
            return;
        }
        chooser.setSelectedFile(new File(chooser.getCurrentDirectory(), file.getName()));
        int ok = chooser.showSaveDialog(this);
        if (ok != JFileChooser.APPROVE_OPTION) {
            return;
        }
        FileOutputStream fout = null;
        RFileInputStream in = null;
        try {
            fout = new FileOutputStream(chooser.getSelectedFile());
            in = new RFileInputStream(file);
            IOUtils.copy(in, fout);
            JOptionPane.showMessageDialog(this, "File downloaded to " + chooser.getSelectedFile(), "Download finished", JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException iOException) {
            JOptionPane.showMessageDialog(this, "Error: " + iOException, "Error", JOptionPane.ERROR_MESSAGE);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Throwable t) {
                }
            }
            if (fout != null) {
                try {
                    fout.close();
                } catch (Throwable t) {
                }
            }
        }
    }
public File takeFile(File f, String prefix, String suffix) throws IOException {
        File nf = createNewFile(prefix, suffix);
        FileInputStream fis = new FileInputStream(f);
        FileChannel fic = fis.getChannel();
        FileOutputStream fos = new FileOutputStream(nf);
        FileChannel foc = fos.getChannel();
        foc.transferFrom(fic, 0, fic.size());
        foc.close();
        fic.close();
        f.delete();
        return nf;
    }
public void SplitFile(File in, File out0, File out1, long pos) throws IOException {
        FileInputStream fis = new FileInputStream(in);
        FileOutputStream fos = new FileOutputStream(out0);
        FileChannel fic = fis.getChannel();
        FileChannel foc = fos.getChannel();
        foc.transferFrom(fic, 0, pos);
        foc.close();
        fos = new FileOutputStream(out1);
        foc = fos.getChannel();
        foc.transferFrom(fic, 0, fic.size() - pos);
        foc.close();
        fic.close();
    }
public File copyFile(File f) throws IOException {
        File t = createNewFile("fm", "cpy");
        FileOutputStream fos = new FileOutputStream(t);
        FileChannel foc = fos.getChannel();
        FileInputStream fis = new FileInputStream(f);
        FileChannel fic = fis.getChannel();
        foc.transferFrom(fic, 0, fic.size());
        foc.close();
        fic.close();
        return t;
    }
public String getMD5Str(String str) {
        MessageDigest messageDigest = null;
        String mdStr = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(str.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException caught!");
            System.exit(-1);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte[] byteArray = messageDigest.digest();
        StringBuffer md5StrBuff = new StringBuffer();
        for (int i = 0; i < byteArray.length; i++) {
            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
        }
        mdStr = md5StrBuff.toString();
        return mdStr;
    }
public static void main(String[] args) {
        boolean rotateLeft = false;
        boolean rotateRight = false;
        boolean exclude = false;
        boolean reset = false;
        float quality = 0f;
        int thumbArea = 12000;
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-rotl")) rotateLeft = true; else if (args[i].equals("-rotr")) rotateRight = true; else if (args[i].equals("-exclude")) exclude = true; else if (args[i].equals("-reset")) reset = true; else if (args[i].equals("-quality")) quality = Float.parseFloat(args[++i]); else if (args[i].equals("-area")) thumbArea = Integer.parseInt(args[++i]); else {
                File f = new File(args[i]);
                try {
                    Tools t = new Tools(f);
                    if (exclude) {
                        URL url = t.getClass().getResource("exclude.jpg");
                        InputStream is = url.openStream();
                        File dest = t.getExcludeFile();
                        OutputStream os = new FileOutputStream(dest);
                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = is.read(buf)) > 0) os.write(buf, 0, len);
                        os.close();
                        is.close();
                        t.getOutFile().delete();
                        t.getThumbFile().delete();
                        System.exit(0);
                    }
                    if (reset) {
                        t.getOutFile().delete();
                        t.getThumbFile().delete();
                        t.getExcludeFile().delete();
                        System.exit(0);
                    }
                    if (quality > 0) t.setQuality(quality);
                    if (t.getType() == Tools.THUMB || t.getType() == Tools.EXCLUDE) t.load(t.getBaseFile()); else t.load(t.getSourceFile());
                    File out = t.getOutFile();
                    if (rotateLeft) t.rotateLeft(); else if (rotateRight) t.rotateRight();
                    t.save(out);
                    t.getExcludeFile().delete();
                    t.getThumbFile().delete();
                    System.exit(0);
                } catch (Throwable e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "The operation could not be performed", "JPhotoAlbum", JOptionPane.ERROR_MESSAGE);
                    System.exit(1);
                }
            }
        }
    }
@Override
    public byte[] getAvatar() throws IOException {
        HttpUriRequest request;
        try {
            request = new HttpGet(mUrl);
        } catch (IllegalArgumentException e) {
            IOException ioe = new IOException("Invalid url " + mUrl);
            ioe.initCause(e);
            throw ioe;
        }
        HttpResponse response = mClient.execute(request);
        HttpEntity entity = response.getEntity();
        InputStream in = entity.getContent();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            byte[] data = new byte[1024];
            int nbread;
            while ((nbread = in.read(data)) != -1) {
                os.write(data, 0, nbread);
            }
        } finally {
            in.close();
            os.close();
        }
        return os.toByteArray();
    }
public static String compute(String text) {
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            byte[] md5hash = new byte[32];
            md.update(text.getBytes("UTF-8"), 0, text.length());
            md5hash = md.digest();
            return convertToHex(md5hash);
        } catch (NoSuchAlgorithmException nax) {
            RuntimeException rx = new IllegalStateException();
            rx.initCause(rx);
            throw rx;
        } catch (UnsupportedEncodingException uex) {
            RuntimeException rx = new IllegalStateException();
            rx.initCause(uex);
            throw rx;
        }
    }
public static byte[] getURLContent(String urlPath) {
        HttpURLConnection conn = null;
        InputStream inStream = null;
        byte[] buffer = null;
        try {
            URL url = new URL(urlPath);
            HttpURLConnection.setFollowRedirects(false);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setDefaultUseCaches(false);
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(60000);
            conn.connect();
            int repCode = conn.getResponseCode();
            if (repCode == 200) {
                inStream = conn.getInputStream();
                int contentLength = conn.getContentLength();
                buffer = getResponseBody(inStream, contentLength);
            }
        } catch (Exception ex) {
            logger.error("", ex);
        } finally {
            try {
                if (inStream != null) {
                    inStream.close();
                }
                if (conn != null) {
                    conn.disconnect();
                }
            } catch (Exception ex) {
            }
        }
        return buffer;
    }
public static String getURLContent(String urlPath, String charset) {
        BufferedReader reader = null;
        HttpURLConnection conn = null;
        StringBuffer buffer = new StringBuffer();
        try {
            URL url = new URL(urlPath);
            HttpURLConnection.setFollowRedirects(false);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setDefaultUseCaches(false);
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(60000);
            conn.connect();
            int repCode = conn.getResponseCode();
            if (repCode == 200) {
                int count = 0;
                char[] chBuffer = new char[1024];
                BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
                while ((count = input.read(chBuffer)) != -1) {
                    buffer.append(chBuffer, 0, count);
                }
            }
        } catch (Exception ex) {
            logger.error("", ex);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
                if (conn != null) {
                    conn.disconnect();
                }
            } catch (Exception ex) {
            }
        }
        return buffer.toString();
    }
public static String getURLContent(String urlPath, String requestData, String charset) {
        BufferedReader reader = null;
        HttpURLConnection conn = null;
        StringBuffer buffer = new StringBuffer();
        OutputStreamWriter out = null;
        try {
            URL url = new URL(urlPath);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setDefaultUseCaches(false);
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(60000);
            out = new OutputStreamWriter(conn.getOutputStream(), charset);
            out.write(requestData);
            out.flush();
            int repCode = conn.getResponseCode();
            if (repCode == 200) {
                int count = 0;
                char[] chBuffer = new char[1024];
                BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
                while ((count = input.read(chBuffer)) != -1) {
                    buffer.append(chBuffer, 0, count);
                }
            }
        } catch (Exception ex) {
            logger.error("", ex);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (reader != null) {
                    reader.close();
                }
                if (conn != null) {
                    conn.disconnect();
                }
            } catch (Exception ex) {
            }
        }
        return buffer.toString();
    }
public static void copy(File src, File dest) throws IOException {
        OutputStream stream = new FileOutputStream(dest);
        FileInputStream fis = new FileInputStream(src);
        byte[] buffer = new byte[16384];
        while (fis.available() != 0) {
            int read = fis.read(buffer);
            stream.write(buffer, 0, read);
        }
        stream.flush();
    }
public void run() {
        FileInputStream src;
        FileOutputStream dest;
        try {
            src = new FileInputStream(srcName);
            dest = new FileOutputStream(destName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        FileChannel srcC = src.getChannel();
        FileChannel destC = dest.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);
        try {
            int i;
            System.out.println(srcC.size());
            while ((i = srcC.read(buf)) > 0) {
                System.out.println(buf.getChar(2));
                buf.flip();
                destC.write(buf);
                buf.compact();
            }
            destC.close();
            dest.close();
        } catch (IOException e1) {
            e1.printStackTrace();
            return;
        }
    }
@RequestMapping(value = "/privatefiles/{file_name}")
    public void getFile(@PathVariable("file_name") String fileName, HttpServletResponse response, Principal principal) {
        try {
            Boolean validUser = false;
            final String currentUser = principal.getName();
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            if (!auth.getPrincipal().equals(new String("anonymousUser"))) {
                MetabolightsUser metabolightsUser = (MetabolightsUser) auth.getPrincipal();
                if (metabolightsUser != null && metabolightsUser.isCurator()) validUser = true;
            }
            if (currentUser != null) {
                Study study = studyService.getBiiStudy(fileName, true);
                Collection<User> users = study.getUsers();
                Iterator<User> iter = users.iterator();
                while (iter.hasNext()) {
                    User user = iter.next();
                    if (user.getUserName().equals(currentUser)) {
                        validUser = true;
                        break;
                    }
                }
            }
            if (!validUser) throw new RuntimeException(PropertyLookup.getMessage("Entry.notAuthorised"));
            try {
                InputStream is = new FileInputStream(privateFtpDirectory + fileName + ".zip");
                response.setContentType("application/zip");
                IOUtils.copy(is, response.getOutputStream());
            } catch (Exception e) {
                throw new RuntimeException(PropertyLookup.getMessage("Entry.fileMissing"));
            }
            response.flushBuffer();
        } catch (IOException ex) {
            logger.info("Error writing file to output stream. Filename was '" + fileName + "'");
            throw new RuntimeException("IOError writing file to output stream");
        }
    }
private Document getOpenLinkResponse(String queryDoc) throws IOException, UnvalidResponseException {
        URL url = new URL(WS_URI);
        URLConnection conn = url.openConnection();
        logger.debug(".conn open");
        conn.setDoOutput(true);
        conn.setRequestProperty("Content-Type", "text/xml");
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(queryDoc);
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        logger.debug(".resp obtained");
        StringBuffer responseBuffer = new StringBuffer();
        String line;
        while ((line = rd.readLine()) != null) {
            responseBuffer.append(line);
            responseBuffer.append(NEWLINE);
        }
        wr.close();
        rd.close();
        logger.debug(".done");
        try {
            return documentParser.parse(responseBuffer.toString());
        } catch (SAXException e) {
            throw new UnvalidResponseException("Response is not a valid XML file", e);
        }
    }
private void fetch() throws IOException {
        if (getAttachmentUrl() != null && (!getAttachmentUrl().isEmpty())) {
            InputStream input = null;
            ByteArrayOutputStream output = null;
            try {
                URL url = new URL(getAttachmentUrl());
                input = url.openStream();
                output = new ByteArrayOutputStream();
                int i;
                while ((i = input.read()) != -1) {
                    output.write(i);
                }
                this.data = output.toByteArray();
            } finally {
                if (input != null) {
                    input.close();
                }
                if (output != null) {
                    output.close();
                }
            }
        }
    }
void download() throws DownloaderException {
        final HttpClient client = new DefaultHttpClient();
        try {
            final FileOutputStream fos = this.activity.openFileOutput(APK_FILENAME, Context.MODE_WORLD_READABLE);
            final HttpResponse response = client.execute(new HttpGet(URL));
            downloadFile(response, fos);
            fos.close();
        } catch (ClientProtocolException e) {
            throw new DownloaderException(e);
        } catch (IOException e) {
            throw new DownloaderException(e);
        }
    }
public static void main(String[] args) throws Exception {
        String linesep = System.getProperty("line.separator");
        FileOutputStream fos = new FileOutputStream(new File("lib-licenses.txt"));
        fos.write(new String("JCP contains the following libraries. Please read this for comments on copyright etc." + linesep + linesep).getBytes());
        fos.write(new String("Chemistry Development Kit, master version as of " + new Date().toString() + " (http://cdk.sf.net)" + linesep).getBytes());
        fos.write(new String("Copyright 1997-2009 The CDK Development Team" + linesep).getBytes());
        fos.write(new String("License: LGPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)" + linesep).getBytes());
        fos.write(new String("Download: https://sourceforge.net/projects/cdk/files/" + linesep).getBytes());
        fos.write(new String("Source available at: http://sourceforge.net/scm/?type=git&group_id=20024" + linesep + linesep).getBytes());
        File[] files = new File(args[0]).listFiles(new JarFileFilter());
        for (int i = 0; i < files.length; i++) {
            if (new File(files[i].getPath() + ".meta").exists()) {
                Map<String, Map<String, String>> metaprops = readProperties(new File(files[i].getPath() + ".meta"));
                Iterator<String> itsect = metaprops.keySet().iterator();
                while (itsect.hasNext()) {
                    String section = itsect.next();
                    fos.write(new String(metaprops.get(section).get("Library") + " " + metaprops.get(section).get("Version") + " (" + metaprops.get(section).get("Homepage") + ")" + linesep).getBytes());
                    fos.write(new String("Copyright " + metaprops.get(section).get("Copyright") + linesep).getBytes());
                    fos.write(new String("License: " + metaprops.get(section).get("License") + " (" + metaprops.get(section).get("LicenseURL") + ")" + linesep).getBytes());
                    fos.write(new String("Download: " + metaprops.get(section).get("Download") + linesep).getBytes());
                    fos.write(new String("Source available at: " + metaprops.get(section).get("SourceCode") + linesep + linesep).getBytes());
                }
            }
            if (new File(files[i].getPath() + ".extra").exists()) {
                fos.write(new String("The author says:" + linesep).getBytes());
                FileInputStream in = new FileInputStream(new File(files[i].getPath() + ".extra"));
                int len;
                byte[] buf = new byte[1024];
                while ((len = in.read(buf)) > 0) {
                    fos.write(buf, 0, len);
                }
            }
            fos.write(linesep.getBytes());
        }
        fos.close();
    }
private void renderScript(PhaseEvent event) {
        URL url = AjaxPhaseListener.class.getResource(SCRIPT_RESOURCE_NAME);
        URLConnection conn = null;
        InputStream stream = null;
        BufferedReader bufReader = null;
        HttpServletResponse response = (HttpServletResponse) event.getFacesContext().getExternalContext().getResponse();
        OutputStreamWriter outWriter = null;
        String curLine = null;
        try {
            outWriter = new OutputStreamWriter(response.getOutputStream(), response.getCharacterEncoding());
            conn = url.openConnection();
            conn.setUseCaches(false);
            stream = conn.getInputStream();
            bufReader = new BufferedReader(new InputStreamReader(stream));
            response.setContentType("text/javascript");
            response.setStatus(200);
            while (null != (curLine = bufReader.readLine())) {
                outWriter.write(curLine + "\n");
            }
            outWriter.flush();
            outWriter.close();
            event.getFacesContext().responseComplete();
        } catch (Exception e) {
            String message = null;
            message = "Can't load script file:" + url.toExternalForm();
        }
    }
@Override
    public void loadData() {
        try {
            String url = "http://ichart.finance.yahoo.com/table.csv?s=" + symbol + "&a=00&b=2&c=1962&d=11&e=11&f=2099&g=d&ignore=.csv";
            URLConnection conn = (new URL(url)).openConnection();
            conn.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            in.readLine();
            String str = "";
            while ((str = in.readLine()) != null) {
                final String[] split = str.split(",");
                final String date = split[0];
                final double open = Double.parseDouble(split[1]);
                final double high = Double.parseDouble(split[2]);
                final double low = Double.parseDouble(split[3]);
                final double close = Double.parseDouble(split[4]);
                final int volume = Integer.parseInt(split[5]);
                final double adjClose = Double.parseDouble(split[6]);
                final HistoricalPrice price = new HistoricalPrice(date, open, high, low, close, volume, adjClose);
                historicalPrices.add(price);
            }
            in.close();
            url = "http://ichart.finance.yahoo.com/table.csv?s=" + symbol + "&a=00&b=2&c=1962&d=11&e=17&f=2008&g=v&ignore=.csv";
            conn = (new URL(url)).openConnection();
            conn.connect();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            in.readLine();
            str = "";
            while ((str = in.readLine()) != null) {
                final String[] split = str.split(",");
                final String date = split[0];
                final double amount = Double.parseDouble(split[1]);
                final Dividend dividend = new Dividend(date, amount);
                dividends.add(dividend);
            }
            in.close();
        } catch (final IOException ioe) {
            logger.error("Error parsing historical prices for " + getSymbol(), ioe);
        }
    }
public static InputStream getInputStream(String filepath) throws Exception {
        if (isUrl(filepath)) {
            URL url = URI.create(filepath).toURL();
            return url.openStream();
        } else {
            return new FileInputStream(new File(filepath));
        }
    }