Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions aws/src/main/java/com/baeldung/s3/S3Application.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.baeldung.s3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
Expand All @@ -28,7 +29,7 @@ public class S3Application {
"<AWS accesskey>",
"<AWS secretkey>"
);
}
}

public static void main(String[] args) throws IOException {
//set-up the client
Expand Down Expand Up @@ -74,15 +75,7 @@ public static void main(String[] args) throws IOException {
//downloading an object
S3Object s3object = awsService.getObject(bucketName, "Document/hello.txt");
S3ObjectInputStream inputStream = s3object.getObjectContent();
FileOutputStream fos = new FileOutputStream(new File("/Users/user/Desktop/hello.txt"));

int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
fos.write(bytes, 0, read);
}
inputStream.close();
fos.close();
FileUtils.copyInputStreamToFile(inputStream, new File("/Users/user/Desktop/hello.txt"));

//copying an object
awsService.copyObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

public class AppleProduct implements Serializable {

private static final long serialVersionUID = 1234567L; // user-defined (i.e. not default or generated)
// private static final long serialVersionUID = 7654321L; // user-defined (i.e. not default or generated)
private static final long serialVersionUID = 1234567L; // user-defined (i.e. not default or generated)
// private static final long serialVersionUID = 7654321L; // user-defined (i.e. not default or generated)

public String headphonePort;
public String thunderboltPort;
public String lighteningPort;
public String lightningPort;

public String getHeadphonePort() {
return headphonePort;
Expand All @@ -23,4 +23,8 @@ public static long getSerialVersionUID() {
return serialVersionUID;
}

public String getLightningPort() {
return lightningPort;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ public class DeserializationUtility {

public static void main(String[] args) throws ClassNotFoundException, IOException {

String serializedObj = "rO0ABXNyACljb20uYmFlbGR1bmcuZGVzZXJpYWxpemF0aW9uLkFwcGxlUHJvZHVjdAAAAAAAEtaHAgADTAANaGVhZHBob25lUG9ydHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wADmxpZ2h0ZW5pbmdQb3J0cQB+AAFMAA90aHVuZGVyYm9sdFBvcnRxAH4AAXhwdAARaGVhZHBob25lUG9ydDIwMjBwdAATdGh1bmRlcmJvbHRQb3J0MjAyMA==";
String serializedObj = "rO0ABXNyACljb20uYmFlbGR1bmcuZGVzZXJpYWxpemF0aW9uLkFwcGxlUHJvZHVjdAAAAAAAEtaHAgADTAANaGVhZHBob25lUG9ydHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wADWxpZ2h0bmluZ1BvcnRxAH4AAUwAD3RodW5kZXJib2x0UG9ydHEAfgABeHB0ABFoZWFkcGhvbmVQb3J0MjAyMHQAEWxpZ2h0bmluZ1BvcnQyMDIwdAATdGh1bmRlcmJvbHRQb3J0MjAyMA==";
System.out.println("Deserializing AppleProduct...");
AppleProduct deserializedObj = (AppleProduct) deSerializeObjectFromString(serializedObj);
System.out.println("Headphone port of AppleProduct:" + deserializedObj.getHeadphonePort());
System.out.println("Thunderbolt port of AppleProduct:" + deserializedObj.getThunderboltPort());
System.out.println("LightningPort port of AppleProduct:" + deserializedObj.getLightningPort());
}

public static Object deSerializeObjectFromString(String s) throws IOException, ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static void main(String[] args) throws ClassNotFoundException, IOExceptio
AppleProduct macBook = new AppleProduct();
macBook.headphonePort = "headphonePort2020";
macBook.thunderboltPort = "thunderboltPort2020";
macBook.lightningPort = "lightningPort2020";

String serializedObj = serializeObjectToString(macBook);
System.out.println("Serialized AppleProduct object to string:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class DeserializationUnitTest {

private static final String serializedObj = "rO0ABXNyACljb20uYmFlbGR1bmcuZGVzZXJpYWxpemF0aW9uLkFwcGxlUHJvZHVjdAAAAAAAEtaHAgADTAANaGVhZHBob25lUG9ydHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wADmxpZ2h0ZW5pbmdQb3J0cQB+AAFMAA90aHVuZGVyYm9sdFBvcnRxAH4AAXhwdAARaGVhZHBob25lUG9ydDIwMjBwdAATdGh1bmRlcmJvbHRQb3J0MjAyMA==";
private static final String serializedObj = "rO0ABXNyACljb20uYmFlbGR1bmcuZGVzZXJpYWxpemF0aW9uLkFwcGxlUHJvZHVjdAAAAAAAdMuxAgADTAANaGVhZHBob25lUG9ydHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wADWxpZ2h0bmluZ1BvcnRxAH4AAUwAD3RodW5kZXJib2x0UG9ydHEAfgABeHB0ABFoZWFkcGhvbmVQb3J0MjAyMHQAEWxpZ2h0bmluZ1BvcnQyMDIwdAATdGh1bmRlcmJvbHRQb3J0MjAyMA";

private static long userDefinedSerialVersionUID = 1234567L;

Expand All @@ -25,20 +25,22 @@ public class DeserializationUnitTest {
public void testDeserializeObj_compatible() throws IOException, ClassNotFoundException {

assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());

AppleProduct macBook = new AppleProduct();
macBook.headphonePort = "headphonePort2020";
macBook.thunderboltPort = "thunderboltPort2020";

macBook.lightningPort = "lightningPort2020";

// serializes the "AppleProduct" object
String serializedProduct = SerializationUtility.serializeObjectToString(macBook);

// deserializes the "AppleProduct" object
AppleProduct deserializedProduct = (AppleProduct) DeserializationUtility.deSerializeObjectFromString(serializedProduct);

assertTrue(deserializedProduct.headphonePort.equalsIgnoreCase(macBook.headphonePort));
assertTrue(deserializedProduct.thunderboltPort.equalsIgnoreCase(macBook.thunderboltPort));

assertTrue(deserializedProduct.lightningPort.equalsIgnoreCase(macBook.lightningPort));

}

/**
Expand All @@ -59,7 +61,6 @@ public void testDeserializeObj_compatible() throws IOException, ClassNotFoundExc
public void testDeserializeObj_incompatible() throws ClassNotFoundException, IOException {

assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());

// attempts to deserialize the "AppleProduct" object
DeserializationUtility.deSerializeObjectFromString(serializedObj);
}
Expand Down
29 changes: 8 additions & 21 deletions libraries/src/main/java/com/baeldung/vaadin/VaadinUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.servlet.annotation.WebServlet;

Expand Down Expand Up @@ -216,7 +219,11 @@ protected void init(VaadinRequest vaadinRequest) {
timeLayout.addComponent(currentTime);
serverPushPanel.setContent(timeLayout);
serverPushPanel.setSizeUndefined();
new ServerPushThread().start();
ScheduledExecutorService scheduleExecutor = Executors.newScheduledThreadPool(1);
Runnable task = () -> {
currentTime.setValue("Current Time : " + Instant.now());
};
scheduleExecutor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS);

FormLayout dataBindingLayout = new FormLayout();
dataBindingLayout.setSpacing(true);
Expand Down Expand Up @@ -271,24 +278,4 @@ protected void init(VaadinRequest vaadinRequest) {
@VaadinServletConfiguration(ui = VaadinUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}

class ServerPushThread extends Thread {
@Override
public void run() {
try {
while (true) {
Thread.sleep(1000);
access(new Runnable() {
@Override
public void run() {
currentTime.setValue("Current Time : " + Instant.now());
}
});
}

} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
17 changes: 17 additions & 0 deletions static-analysis/src/test/java/com/baeldung/pmd/CntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.baeldung.pmd;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class CntTest {

private Cnt service;

@Test
public void whenSecondParamIsZeroShouldReturnIntMax(){
service = new Cnt();
int answer = service.d(100,0);
assertEquals(Integer.MAX_VALUE, answer);
}
}
14 changes: 13 additions & 1 deletion vavr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>


<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
</pluginRepositories>

<properties>
<java.version>1.8</java.version>
<vavr.version>0.9.0</vavr.version>
Expand Down