10 Haziran 2019 Pazartesi
30 Mayıs 2019 Perşembe
Lang3 ToStringBuilder Sınıfı
Giriş
Şu satırı dahil ederiz.
Şöyle yaparız. Sınıf isminin de çıktı olarak gelmesi için constructor içine this ile kendi nesnemizi geçeriz.
Şu satırı dahil ederiz.
import org.apache.commons.lang3.builder.ToStringBuilder;
constructor metodu
Şöyle yaparız. Sınıf isminin de çıktı olarak gelmesi için constructor içine this ile kendi nesnemizi geçeriz.
@Override
public String toString() {
return new ToStringBuilder(this) .append("docmanId", docmanId).
.append("dz", dz)
.toString();
}
28 Mayıs 2019 Salı
BeanUtilsBean Sınıfı
populate metodu
Map içindeki değerleri POJO nesneye atar.
Örnek
Elimizde şöyle bir kod olsun.
Map içindeki değerleri POJO nesneye atar.
Örnek
Elimizde şöyle bir kod olsun.
class POJO{
Integer intField;
Double doubleField
}
Şöyle yaparız.POJO obj = new POJO();
Map<String,String> map = new HashMap<>();
map.put("intField", "1");
map.put("doubleField", "1.1");
BeanUtilsBean.populate(obj, map)
14 Mayıs 2019 Salı
POI Excel DataFormatter Sınıfı
Giriş
Şu satırı dahil ederiz.
constructor
Şöyle yaparız.
Şöyle yaparız.
Şu satırı dahil ederiz.
import org.apache.poi.ss.usermodel.DataFormatter;
Hücredeki değeri aynen Excel'de göründüğü gibi String olarak geri verirconstructor
Şöyle yaparız.
DataFormatter dataFormatter = new DataFormatter();
formatCellValue metoduŞöyle yaparız.
Cell cell = ...;
String cellValue = dataFormatter.formatCellValue(cell);
9 Mayıs 2019 Perşembe
HttpClient Sınıfı - Kullanmayın
Giriş
Şu satırı dahil ederiz.
Şu satırı dahil ederiz.
import org.apache.commons.httpclient.HttpClient;Açıklaması şöyle
Commons HttpClient is an old project that produced HttpClient 3.1. The project was subsumed by the larger Apache HttpComponents project, which produced HttpClient 4.x.
constructor
Örnek - Multipart file uploads
Şöyle yaparız
File file1 = new File("C:\\_tools\\students.xml");File file2 = new File("C:\\_tools\\rules.xml");PostMethod filePost = new PostMethod(url);Part[] parts = {new FilePart(file1.getName(), file1),new FilePart(file2.getName(), file2)};filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));HttpClient client = new HttpClient();int status = client.executeMethod(filePost);
Örnek - HttpPost
Şöyle yaparız.
StringEntity entity = ...
HttpPost post = new HttpPost(URL);
post.setEntity(entity);
HttpResponse response = client.execute(post);
3 Mayıs 2019 Cuma
PropertiesConfiguration Sınıfı
Giri
Şu satırı dahil ederiz.
Şöyle yaparız.
Şöyle yaparız.
Açıklaması şöyle
Şöyle yaparız.
cleartProperty(...) + addProperty(...) gibi çalışır.
Örnek
Şöyle yaparız.
Şu satırı dahil ederiz.
import org.apache.commons.configuration2.PropertiesConfiguration;
constructorŞöyle yaparız.
Configuration config = null;
try {
config = new PropertiesConfiguration("config.properties");
} catch (ConfigurationException e) {
...
}
addProperty metoduŞöyle yaparız.
config.addProperty("VALUE_FACTORY", BVF_extendo4000.INSTANCE);
getLayout metoduAçıklaması şöyle
Each PropertiesConfiguration object is associated with a Layout object, an instance of the class PropertiesConfigurationLayout. This layout object is responsible for preserving most of the structure of loaded configuration files. This means that things like comments or blank lines in a saved properties file will closely resemble the original properties file (the algorithm is not 100 percent perfect, but for most use cases it should be sufficient).Şöyle yaparız.
PropertiesConfigurationLayout layout = config.getLayout();
save metoduŞöyle yaparız.
config.save( new FileWriter( "c:/try/out.props"));
setProperty metoducleartProperty(...) + addProperty(...) gibi çalışır.
Örnek
Şöyle yaparız.
PropertiesConfiguration config = new PropertiesConfiguration("in.properties");
config.setProperty("application.version", "myvar");
1 Mayıs 2019 Çarşamba
FTPSClient Sınıfı
Giriş
Şu satırı dahil ederiz.
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
Server Verification with TLS1.2 için şöyle yaparız.
Şu satırı dahil ederiz.
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
constructorŞöyle yaparız.
FTPSClient ftpClient = new FTPSClient();
connect metoduŞöyle yaparız.
ftpClient.connect("foo.com", 21);
enterLocalPassiveMode metodu
Şöyle yaparız.
ftpClient.enterLocalPassiveMode();
login metoduŞöyle yaparız.
ftpClient.login("login", "password");
setFileType metodu
Şöyle yaparız.
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
setTrustManager metodu
Server Verification with TLS1.2 için şöyle yaparız.
File storeFile = new File("pure-ftpd.jks");
KeyStore keystore = loadKeyStore("JKS", storeFile, "password");
X509TrustManager defaultTM = TrustManagerUtils.getDefaultTrustManager(keystore);
String[] TLSversions = new String[]{"TLSv1.2"};
FTPSClient ftpTLS = new FTPSClient("SSL", false);
ftpTLS.setEnabledProtocols(TLSversions);
ftpTLS.setTrustManager(defaultTM);
ftpTLS.addProtocolCommandListener(new PrintCommandListener(
new PrintWriter(System.out), true));
ftpTLS.setRemoteVerificationEnabled(true);
ftpTLS.setDefaultPort(21);
ftpTLS.connect("127.0.0.1", 21);
Kaydol:
Kayıtlar (Atom)