semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void run() {
                final SimpleMessageListener listener = new SimpleMessageListener() {

                    public final boolean accept(final String from, final String recipient) {
                        return true;
                    }

                    public final void deliver(final String from, final String recipient, final InputStream data) throws TooMuchDataException, IOException {
                        System.out.println("FROM: " + from);
                        System.out.println("TO: " + recipient);
                        final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
                        final File file = new File(tmpDir, recipient);
                        final FileWriter fw = new FileWriter(file);
                        try {
                            IOUtils.copy(data, fw);
                        } finally {
                            fw.close();
                        }
                    }
                };
                final SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(listener));
                smtpServer.start();
                System.out.println("Started SMTP Server");
            }
public final void deliver(final String from, final String recipient, final InputStream data) throws TooMuchDataException, IOException {
                        System.out.println("FROM: " + from);
                        System.out.println("TO: " + recipient);
                        final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
                        final File file = new File(tmpDir, recipient);
                        final FileWriter fw = new FileWriter(file);
                        try {
                            IOUtils.copy(data, fw);
                        } finally {
                            fw.close();
                        }
                    }
@Test
    public final void testCheckCookies() {
        URL url = null;
        try {
            url = new URL("http://localhost:8080");
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        }
        StringBuffer content = new StringBuffer();
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)");
            cookie = connection.getHeaderField("Set-Cookie");
            if (cookie != null) System.out.println("cookie: " + cookie.toString());
            connection.setDoInput(true);
            InputStream is = connection.getInputStream();
            byte[] buffer = new byte[2048];
            int count;
            while (-1 != (count = is.read(buffer))) {
                content.append(new String(buffer, 0, count));
            }
        } catch (IOException e) {
            System.out.print(e.getMessage());
            return;
        }
    }
void loadSVG(String svgFileURL) {
        try {
            URL url = new URL(svgFileURL);
            URLConnection c = url.openConnection();
            c.setRequestProperty("Accept-Encoding", "gzip");
            InputStream is = c.getInputStream();
            String encoding = c.getContentEncoding();
            if ("gzip".equals(encoding) || "x-gzip".equals(encoding) || svgFileURL.toLowerCase().endsWith(".svgz")) {
                is = new GZIPInputStream(is);
            }
            is = new BufferedInputStream(is);
            Document svgDoc = AppletUtils.parse(is, false);
            if (svgDoc != null) {
                if (grMngr.mainView.isBlank() == null) {
                    grMngr.mainView.setBlank(cfgMngr.backgroundColor);
                }
                SVGReader.load(svgDoc, grMngr.mSpace, true, svgFileURL);
                grMngr.seekBoundingBox();
                grMngr.buildLogicalStructure();
                ConfigManager.defaultFont = VText.getMainFont();
                grMngr.reveal();
                if (grMngr.previousLocations.size() == 1) {
                    grMngr.previousLocations.removeElementAt(0);
                }
                if (grMngr.rView != null) {
                    grMngr.rView.getGlobalView(grMngr.mSpace.getCamera(1), 100);
                }
                grMngr.cameraMoved(null, null, 0);
            } else {
                System.err.println("An error occured while loading file " + svgFileURL);
            }
        } catch (Exception ex) {
            grMngr.reveal();
            ex.printStackTrace();
        }
    }
public InputStream sendCommandRaw(String command, boolean usePost) throws IOException {
        try {
            String fullCommand = prefix + command + fixSuffix(command, suffix);
            long curGap = System.currentTimeMillis() - lastCommandTime;
            long delayTime = minimumCommandPeriod - curGap;
            delay(delayTime);
            URI uri = new URI(fullCommand);
            URL url = uri.toURL();
            if (trace || traceSends) {
                System.out.println("Sending-->     " + url);
            }
            if (logFile != null) {
                logFile.println("Sending-->     " + url);
            }
            InputStream is = null;
            for (int i = 0; i < tryCount; i++) {
                try {
                    URLConnection urc = url.openConnection();
                    if (usePost) {
                        if (urc instanceof HttpURLConnection) {
                            ((HttpURLConnection) urc).setRequestMethod("POST");
                        }
                    }
                    if (getTimeout() != -1) {
                        urc.setReadTimeout(getTimeout());
                        urc.setConnectTimeout(getTimeout());
                    }
                    is = new BufferedInputStream(urc.getInputStream());
                    break;
                } catch (FileNotFoundException e) {
                    throw e;
                } catch (IOException e) {
                    System.out.println(name + " Error: " + e + " cmd: " + command);
                }
            }
            lastCommandTime = System.currentTimeMillis();
            if (is == null) {
                System.out.println(name + " retry failure  cmd: " + url);
                throw new IOException("Can't send command");
            }
            return is;
        } catch (URISyntaxException ex) {
            throw new IOException("bad uri " + ex);
        }
    }
public static void loadFile(final URL url, final StringBuffer buffer) throws IOException {
        InputStream in = null;
        BufferedReader dis = null;
        try {
            in = url.openStream();
            dis = new BufferedReader(new InputStreamReader(in));
            int i;
            while ((i = dis.read()) != -1) {
                buffer.append((char) i);
            }
        } finally {
            closeStream(in);
            closeReader(dis);
        }
    }
public static void saveFile(final URL url, final File file) throws IOException {
        final InputStream in = url.openStream();
        final FileOutputStream out = new FileOutputStream(file);
        byte[] data = new byte[8 * 1024];
        int length;
        while ((length = in.read(data)) != -1) {
            out.write(data, 0, length);
        }
        in.close();
        out.close();
    }
private long newIndex(String indexname) {
        Connection con = null;
        ResultSet rs = null;
        Statement stm = null;
        StringBuffer sql = new StringBuffer();
        indexname = indexname.trim().toUpperCase();
        try {
            long index = -1;
            synchronized (FormularContextPersistensImpl.class) {
                con = getConnection();
                stm = con.createStatement();
                if ((con != null) && (stm != null)) {
                    con.setAutoCommit(false);
                    sql = new StringBuffer();
                    sql.append("SELECT * FROM INDX_EC WHERE INDX_NAME='");
                    sql.append(indexname);
                    sql.append("' FOR UPDATE");
                    rs = stm.executeQuery(sql.toString());
                    if ((rs != null) && rs.next()) {
                        sql = new StringBuffer();
                        index = rs.getLong("INDX_WERT") + 1;
                        sql.append("UPDATE INDX_EC SET INDX_WERT = ");
                        sql.append(index);
                        sql.append(" WHERE INDX_NAME='");
                        sql.append(indexname);
                        sql.append("'");
                        rs.close();
                        rs = null;
                        if (stm.executeUpdate(sql.toString()) == 1) {
                            con.commit();
                        } else {
                            con.rollback();
                            index = -1;
                        }
                    } else {
                        sql = new StringBuffer();
                        sql.append("INSERT INTO INDX_EC (INDX_NAME, INDX_WERT) VALUES('");
                        sql.append(indexname);
                        sql.append("', ");
                        sql.append(1);
                        sql.append(")");
                        if (stm.executeUpdate(sql.toString()) == 1) {
                            con.commit();
                            index = 1;
                        } else {
                            con.rollback();
                        }
                    }
                }
            }
            return index;
        } catch (Exception e) {
            Log.getLogger().error("Error during execute SQL-Statement: " + sql.toString(), e);
            return -1;
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception ignore) {
                }
            }
            if (stm != null) {
                try {
                    stm.close();
                } catch (Exception ignore) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ignore) {
                }
            }
        }
    }
private void fileCopier(String filenameFrom, String filenameTo) {
        FileInputStream fromStream = null;
        FileOutputStream toStream = null;
        try {
            fromStream = new FileInputStream(new File(filenameFrom));
            if (new File(filenameTo).exists()) {
                new File(filenameTo).delete();
            }
            File dirr = new File(getContactPicPath());
            if (!dirr.exists()) {
                dirr.mkdir();
            }
            toStream = new FileOutputStream(new File(filenameTo));
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = fromStream.read(buffer)) != -1) toStream.write(buffer, 0, bytesRead);
        } catch (FileNotFoundException e) {
            Errmsg.errmsg(e);
        } catch (IOException e) {
            Errmsg.errmsg(e);
        } finally {
            try {
                if (fromStream != null) {
                    fromStream.close();
                }
                if (toStream != null) {
                    toStream.close();
                }
            } catch (IOException e) {
                Errmsg.errmsg(e);
            }
        }
    }
public void go() throws FBConnectionException, FBErrorException, IOException {
        clearError();
        results = new LoginResults();
        URL url = new URL(getHost() + getPath());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("X-FB-User", getUser());
        conn.setRequestProperty("X-FB-Auth", makeResponse());
        conn.setRequestProperty("X-FB-Mode", "Login");
        conn.setRequestProperty("X-FB-Login.ClientVersion", agent);
        conn.connect();
        Element fbresponse;
        try {
            fbresponse = readXML(conn);
        } catch (FBConnectionException fbce) {
            throw fbce;
        } catch (FBErrorException fbee) {
            throw fbee;
        } catch (Exception e) {
            FBConnectionException fbce = new FBConnectionException("XML parsing failed");
            fbce.attachSubException(e);
            throw fbce;
        }
        NodeList nl = fbresponse.getElementsByTagName("LoginResponse");
        for (int i = 0; i < nl.getLength(); i++) {
            if (nl.item(i) instanceof Element && hasError((Element) nl.item(i))) {
                error = true;
                FBErrorException e = new FBErrorException();
                e.setErrorCode(errorcode);
                e.setErrorText(errortext);
                throw e;
            }
        }
        results.setMessage(DOMUtil.getAllElementText(fbresponse, "Message"));
        results.setServerTime(DOMUtil.getAllElementText(fbresponse, "ServerTime"));
        NodeList quotas = fbresponse.getElementsByTagName("Quota");
        for (int i = 0; i < quotas.getLength(); i++) {
            if (quotas.item(i) instanceof Node) {
                NodeList children = quotas.item(i).getChildNodes();
                for (int j = 0; j < children.getLength(); j++) {
                    if (children.item(j) instanceof Element) {
                        Element working = (Element) children.item(j);
                        if (working.getNodeName().equals("Remaining")) {
                            try {
                                results.setQuotaRemaining(Long.parseLong(DOMUtil.getSimpleElementText(working)));
                            } catch (Exception e) {
                            }
                        }
                        if (working.getNodeName().equals("Used")) {
                            try {
                                results.setQuotaUsed(Long.parseLong(DOMUtil.getSimpleElementText(working)));
                            } catch (Exception e) {
                            }
                        }
                        if (working.getNodeName().equals("Total")) {
                            try {
                                results.setQuotaTotal(Long.parseLong(DOMUtil.getSimpleElementText(working)));
                            } catch (Exception e) {
                            }
                        }
                    }
                }
            }
        }
        results.setRawXML(getLastRawXML());
        return;
    }
public byte[] getResponse() {
        final ByteArrayInputStream bais = new ByteArrayInputStream(request);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        List<String> lines = Collections.emptyList();
        try {
            @SuppressWarnings("unchecked") List<String> dl = IOUtils.readLines(bais);
            lines = dl;
        } catch (IOException ioex) {
            throw new AssertionError(ioex);
        }
        String resource = null;
        for (String line : lines) {
            if (line.startsWith("GET ")) {
                int endIndex = line.lastIndexOf(' ');
                resource = line.substring(4, endIndex);
            }
        }
        final PrintStream printStream = new PrintStream(baos);
        if (resource == null) {
            printStream.println("HTTP/1.1 400 Bad Request");
        } else {
            final InputStream inputStream = getClass().getResourceAsStream(resource);
            if (inputStream == null) {
                printStream.println("HTTP/1.1 404 Not Found");
                printStream.println();
            } else {
                printStream.println("HTTP/1.1 200 OK");
                printStream.println();
                try {
                    IOUtils.copy(inputStream, printStream);
                } catch (IOException ioex) {
                    throw new AssertionError(ioex);
                }
            }
        }
        printStream.flush();
        printStream.close();
        return baos.toByteArray();
    }
public static void copyFile(File srcFile, File destFolder) {
        try {
            File destFile = new File(destFolder, srcFile.getName());
            if (destFile.exists()) {
                throw new BuildException("Could not copy " + srcFile + " to " + destFolder + " as " + destFile + " already exists");
            }
            FileChannel srcChannel = null;
            FileChannel destChannel = null;
            try {
                srcChannel = new FileInputStream(srcFile).getChannel();
                destChannel = new FileOutputStream(destFile).getChannel();
                destChannel.transferFrom(srcChannel, 0, srcChannel.size());
            } finally {
                if (srcChannel != null) {
                    srcChannel.close();
                }
                if (destChannel != null) {
                    destChannel.close();
                }
            }
            destFile.setLastModified((srcFile.lastModified()));
        } catch (IOException e) {
            throw new BuildException("Could not copy " + srcFile + " to " + destFolder + ": " + e, e);
        }
    }
public void actionPerformed(ActionEvent e) {
        if (mode == ADD_URL) {
            String url = JOptionPane.showInputDialog(null, "Enter URL", "Enter URL", JOptionPane.OK_CANCEL_OPTION);
            if (url == null) return;
            try {
                is = new URL(url).openStream();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (mode == ADD_FILE) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.showDialog(null, "Add tab");
            File file = chooser.getSelectedFile();
            if (file == null) return;
            try {
                is = new FileInputStream(file);
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            }
        }
        if (repository == null) repository = PersistenceService.getInstance();
        List artists = repository.getAllArtists();
        EventList artistList = new BasicEventList();
        artistList.addAll(artists);
        addDialog = new AddSongDialog(artistList, JOptionPane.getRootFrame(), true);
        Song s = addDialog.getSong();
        if (is != null) {
            String tab;
            try {
                tab = readTab(is);
                s.setTablature(tab);
                addDialog.setSong(s);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        addDialog.setVisible(true);
        addDialog.addWindowListener(new WindowAdapter() {

            public void windowClosed(WindowEvent e) {
                int ok = addDialog.getReturnStatus();
                if (ok == AddSongDialog.RET_CANCEL) return;
                addSong();
            }
        });
    }
@Override
    public void checkConnection(byte[] options) throws Throwable {
        Properties opts = PropertiesUtils.deserializeProperties(options);
        String server = opts.getProperty(TRANSFER_OPTION_SERVER);
        String username = opts.getProperty(TRANSFER_OPTION_USERNAME);
        String password = opts.getProperty(TRANSFER_OPTION_PASSWORD);
        String filePath = opts.getProperty(TRANSFER_OPTION_FILEPATH);
        URL url = new URL(PROTOCOL_PREFIX + username + ":" + password + "@" + server + filePath + ";type=i");
        URLConnection urlc = url.openConnection(BackEnd.getProxy(Proxy.Type.SOCKS));
        urlc.setConnectTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        urlc.setReadTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        urlc.connect();
    }
@Override
    public void writeData(byte[] data, byte[] options, boolean transferMetaData) throws Throwable {
        long startTime = System.currentTimeMillis();
        long transferredBytesNum = 0;
        long elapsedTime = 0;
        Properties opts = PropertiesUtils.deserializeProperties(options);
        String server = opts.getProperty(TRANSFER_OPTION_SERVER);
        String username = opts.getProperty(TRANSFER_OPTION_USERNAME);
        String password = opts.getProperty(TRANSFER_OPTION_PASSWORD);
        String filePath = opts.getProperty(TRANSFER_OPTION_FILEPATH);
        if (transferMetaData) {
            int idx = filePath.lastIndexOf(PATH_SEPARATOR);
            if (idx != -1) {
                String fileName = filePath.substring(idx + 1) + META_DATA_FILE_SUFIX;
                filePath = filePath.substring(0, idx);
                filePath = filePath + PATH_SEPARATOR + fileName;
            } else {
                filePath += META_DATA_FILE_SUFIX;
            }
        }
        URL url = new URL(PROTOCOL_PREFIX + username + ":" + password + "@" + server + filePath + ";type=i");
        URLConnection urlc = url.openConnection(BackEnd.getProxy(Proxy.Type.SOCKS));
        urlc.setConnectTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        urlc.setReadTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        OutputStream os = urlc.getOutputStream();
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        byte[] buffer = new byte[1024];
        int br;
        while ((br = bis.read(buffer)) > 0) {
            os.write(buffer, 0, br);
            if (!transferMetaData) {
                transferredBytesNum += br;
                elapsedTime = System.currentTimeMillis() - startTime;
                fireOnProgressEvent(transferredBytesNum, elapsedTime);
            }
        }
        bis.close();
        os.close();
    }
@Override
    public byte[] readData(byte[] options, boolean transferMetaData) throws Throwable {
        long startTime = System.currentTimeMillis();
        long transferredBytesNum = 0;
        long elapsedTime = 0;
        Properties opts = PropertiesUtils.deserializeProperties(options);
        String server = opts.getProperty(TRANSFER_OPTION_SERVER);
        String username = opts.getProperty(TRANSFER_OPTION_USERNAME);
        String password = opts.getProperty(TRANSFER_OPTION_PASSWORD);
        String filePath = opts.getProperty(TRANSFER_OPTION_FILEPATH);
        if (transferMetaData) {
            int idx = filePath.lastIndexOf(PATH_SEPARATOR);
            if (idx != -1) {
                String fileName = filePath.substring(idx + 1) + META_DATA_FILE_SUFIX;
                filePath = filePath.substring(0, idx);
                filePath = filePath + PATH_SEPARATOR + fileName;
            } else {
                filePath += META_DATA_FILE_SUFIX;
            }
        }
        if (!server.contains(PORT_SEPARATOR)) {
            server += PORT_SEPARATOR + DEFAULT_PORT;
        }
        URL url = new URL(PROTOCOL_PREFIX + username + ":" + password + "@" + server + filePath + ";type=i");
        URLConnection urlc = url.openConnection(BackEnd.getProxy(Proxy.Type.SOCKS));
        urlc.setConnectTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        urlc.setReadTimeout(Preferences.getInstance().preferredTimeOut * 1000);
        ByteArrayOutputStream baos = null;
        try {
            InputStream is = urlc.getInputStream();
            baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int br;
            while ((br = is.read(buffer)) > 0) {
                baos.write(buffer, 0, br);
                if (!transferMetaData) {
                    transferredBytesNum += br;
                    elapsedTime = System.currentTimeMillis() - startTime;
                    fireOnProgressEvent(transferredBytesNum, elapsedTime);
                }
            }
            baos.close();
            is.close();
        } catch (FileNotFoundException fnfe) {
        }
        return baos != null ? baos.toByteArray() : null;
    }