I have been working with IntelliJ IDEA 14 in Ubuntu for a long time. Some times I experienced a sudden failure of keyboard not working for IDEA and you can't type anything in editor and any of the shortcuts are not working at all.
Initially I restarted the IDEA and worked again, but that's a big hassle as I have to always restart the Wildfly and this may kill time as when this issue happens frequently. But executing below command in terminal is working for this issue and you don't need to restart the IDEA.
ibus-daemon -rd
Friday, February 12, 2016
Tuesday, February 9, 2016
Resolve Video Playing Issue in VLC Player on Ubuntu
Recently when I was trying to play a video file using VLC in my ubuntu OS, it only showed a black screen with background sounds. Tried few ways and following worked to resolve the issue.
1. Open VLC player
2. Click Tools
3. Select Preferences
4. Select Video
5. Click drop down in output and select "OpenGL GLX Video output(XCB)"
(default, it was "Automatic").
6.Click Save and Then play the video
1. Open VLC player
2. Click Tools
3. Select Preferences
4. Select Video
5. Click drop down in output and select "OpenGL GLX Video output(XCB)"
(default, it was "Automatic").
6.Click Save and Then play the video
Monday, February 1, 2016
SFTP File Uploading/Downloading Using Java
Recently I got a requirement to upload a file to host using a java program. I used Jsch library and below is the maven dependency required
Using above library, below is a simple util class which you can use with SFTP on java.
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.53</version>
</dependency>
Using above library, below is a simple util class which you can use with SFTP on java.
import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.ProxyHTTP; import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException; /** * Utility class to upload or download files via SFTP * * @author : chamara */ public class SFTPFileUtil { private Session session = null; private ChannelSftp sftpChannel = null; private String host = null; private int port = 22; private String username = null; private String password = null; private String strictHostChk = "no"; private final String SFTP_PROTOCOL = "sftp"; private boolean useHttpProxy = false; private String httpProxyHost = null; private int httpProxyPort; public SFTPFileUtil(String host, String username, String password) { this.host = host; this.username = username; this.password = password; } public SFTPFileUtil(String host, int port, String username, String password) { this.host = host; this.port = port; this.username = username; this.password = password; } public void connectAndLogin() throws JSchException { if (session == null || !session.isConnected()) { JSch jsch = new JSch(); session = jsch.getSession(username, host, port); session.setConfig("StrictHostKeyChecking", strictHostChk); session.setPassword(password); if (isUseHttpProxy()) { session.setProxy(new ProxyHTTP(getHttpProxyHost(), getHttpProxyPort())); } session.connect(); } if (sftpChannel == null || sftpChannel.isClosed()) { Channel channel = session.openChannel(SFTP_PROTOCOL); channel.connect(); sftpChannel = (ChannelSftp) channel; } } public void closeAndLogout() { if (sftpChannel != null) { sftpChannel.exit(); } if (session != null) { session.disconnect(); } } @Override protected void finalize() throws Throwable { closeAndLogout(); super.finalize(); } private boolean isUseHttpProxy() { return useHttpProxy; } public void setHttpProxy(String httpHost, Integer httpPort) { if (httpHost != null && !"".equals(httpHost.trim()) && httpPort != null && httpPort > 0) { this.useHttpProxy = true; this.httpProxyHost = httpHost; this.httpProxyPort = httpPort; } else { this.useHttpProxy = false; } } private String getHttpProxyHost() { return httpProxyHost; } private int getHttpProxyPort() { return httpProxyPort; } public void changeDirectory(String path) throws SftpException, JSchException { connectAndLogin(); sftpChannel.cd(path); } public void uploadFile(String localPath) throws SftpException, JSchException { connectAndLogin(); sftpChannel.put(localPath); } public void uploadFile(String localPath, String remotePath) throws SftpException, JSchException { connectAndLogin(); sftpChannel.put(localPath, remotePath); } public void downloadFile(String localPath, String remotePath) throws SftpException, JSchException { connectAndLogin(); sftpChannel.get(remotePath,localPath); } public static void main(String[] args){ SFTPFileUtil fileUtil = new SFTPFileUtil("[host name]","[user name]","[password]"); try { fileUtil.uploadFile("[local file path]","[remote directory path]"); } catch (SftpException e) { e.printStackTrace(); } catch (JSchException e) { e.printStackTrace(); } fileUtil.closeAndLogout(); } }
Subscribe to:
Comments (Atom)
