Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
d6b5ee4810
|
@ -17,6 +17,11 @@
|
|||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -28,6 +33,7 @@
|
|||
<artifactId>tradukisto</artifactId>
|
||||
<version>${tradukisto.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
@ -52,6 +58,7 @@
|
|||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,83 @@
|
|||
package com.baeldung.algorithms.caesarcipher;
|
||||
|
||||
import org.apache.commons.math3.stat.inference.ChiSquareTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class CaesarCipher {
|
||||
private static final char LETTER_A = 'a';
|
||||
private static final char LETTER_Z = 'z';
|
||||
private static final int ALPHABET_SIZE = LETTER_Z - LETTER_A + 1;
|
||||
private static final double[] ENGLISH_LETTERS_PROBABILITIES = {0.073, 0.009, 0.030, 0.044, 0.130, 0.028, 0.016, 0.035, 0.074, 0.002, 0.003, 0.035, 0.025, 0.078, 0.074, 0.027, 0.003, 0.077, 0.063, 0.093, 0.027, 0.013, 0.016, 0.005, 0.019, 0.001};
|
||||
|
||||
public String cipher(String message, int offset) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (char character : message.toCharArray()) {
|
||||
if (character != ' ') {
|
||||
int originalAlphabetPosition = character - LETTER_A;
|
||||
int newAlphabetPosition = (originalAlphabetPosition + offset) % ALPHABET_SIZE;
|
||||
char newCharacter = (char) (LETTER_A + newAlphabetPosition);
|
||||
result.append(newCharacter);
|
||||
} else {
|
||||
result.append(character);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String decipher(String message, int offset) {
|
||||
return cipher(message, ALPHABET_SIZE - (offset % ALPHABET_SIZE));
|
||||
}
|
||||
|
||||
public int breakCipher(String message) {
|
||||
return probableOffset(chiSquares(message));
|
||||
}
|
||||
|
||||
private double[] chiSquares(String message) {
|
||||
double[] expectedLettersFrequencies = expectedLettersFrequencies(message.length());
|
||||
|
||||
double[] chiSquares = new double[ALPHABET_SIZE];
|
||||
|
||||
for (int offset = 0; offset < chiSquares.length; offset++) {
|
||||
String decipheredMessage = decipher(message, offset);
|
||||
long[] lettersFrequencies = observedLettersFrequencies(decipheredMessage);
|
||||
double chiSquare = new ChiSquareTest().chiSquare(expectedLettersFrequencies, lettersFrequencies);
|
||||
chiSquares[offset] = chiSquare;
|
||||
}
|
||||
|
||||
return chiSquares;
|
||||
}
|
||||
|
||||
private long[] observedLettersFrequencies(String message) {
|
||||
return IntStream.rangeClosed(LETTER_A, LETTER_Z)
|
||||
.mapToLong(letter -> countLetter((char) letter, message))
|
||||
.toArray();
|
||||
}
|
||||
|
||||
private long countLetter(char letter, String message) {
|
||||
return message.chars()
|
||||
.filter(character -> character == letter)
|
||||
.count();
|
||||
}
|
||||
|
||||
private double[] expectedLettersFrequencies(int messageLength) {
|
||||
return Arrays.stream(ENGLISH_LETTERS_PROBABILITIES)
|
||||
.map(probability -> probability * messageLength)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
private int probableOffset(double[] chiSquares) {
|
||||
int probableOffset = 0;
|
||||
for (int offset = 0; offset < chiSquares.length; offset++) {
|
||||
System.out.println(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset]));
|
||||
if (chiSquares[offset] < chiSquares[probableOffset]) {
|
||||
probableOffset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
return probableOffset;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.baeldung.algorithms.caesarcipher;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CaesarCipherUnitTest {
|
||||
private static final String SENTENCE = "he told me i could never teach a llama to drive";
|
||||
private static final String SENTENCE_SHIFTED_THREE = "kh wrog ph l frxog qhyhu whdfk d oodpd wr gulyh";
|
||||
private static final String SENTENCE_SHIFTED_TEN = "ro dyvn wo s myevn xofob dokmr k vvkwk dy nbsfo";
|
||||
|
||||
private CaesarCipher algorithm = new CaesarCipher();
|
||||
|
||||
@Test
|
||||
void givenSentenceAndShiftThree_whenCipher_thenCipheredMessageWithoutOverflow() {
|
||||
String cipheredSentence = algorithm.cipher(SENTENCE, 3);
|
||||
|
||||
assertThat(cipheredSentence)
|
||||
.isEqualTo(SENTENCE_SHIFTED_THREE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceAndShiftTen_whenCipher_thenCipheredMessageWithOverflow() {
|
||||
String cipheredSentence = algorithm.cipher(SENTENCE, 10);
|
||||
|
||||
assertThat(cipheredSentence)
|
||||
.isEqualTo(SENTENCE_SHIFTED_TEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceAndShiftThirtySix_whenCipher_thenCipheredLikeTenMessageWithOverflow() {
|
||||
String cipheredSentence = algorithm.cipher(SENTENCE, 36);
|
||||
|
||||
assertThat(cipheredSentence)
|
||||
.isEqualTo(SENTENCE_SHIFTED_TEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceShiftedThreeAndShiftThree_whenDecipher_thenOriginalSentenceWithoutOverflow() {
|
||||
String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_THREE, 3);
|
||||
|
||||
assertThat(decipheredSentence)
|
||||
.isEqualTo(SENTENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceShiftedTenAndShiftTen_whenDecipher_thenOriginalSentenceWithOverflow() {
|
||||
String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_TEN, 10);
|
||||
|
||||
assertThat(decipheredSentence)
|
||||
.isEqualTo(SENTENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceShiftedTenAndShiftThirtySix_whenDecipher_thenOriginalSentenceWithOverflow() {
|
||||
String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_TEN, 36);
|
||||
|
||||
assertThat(decipheredSentence)
|
||||
.isEqualTo(SENTENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceShiftedThree_whenBreakCipher_thenOriginalSentence() {
|
||||
int offset = algorithm.breakCipher(SENTENCE_SHIFTED_THREE);
|
||||
|
||||
assertThat(offset)
|
||||
.isEqualTo(3);
|
||||
|
||||
assertThat(algorithm.decipher(SENTENCE_SHIFTED_THREE, offset))
|
||||
.isEqualTo(SENTENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenSentenceShiftedTen_whenBreakCipher_thenOriginalSentence() {
|
||||
int offset = algorithm.breakCipher(SENTENCE_SHIFTED_TEN);
|
||||
|
||||
assertThat(offset)
|
||||
.isEqualTo(10);
|
||||
|
||||
assertThat(algorithm.decipher(SENTENCE_SHIFTED_TEN, offset))
|
||||
.isEqualTo(SENTENCE);
|
||||
}
|
||||
}
|
|
@ -7,15 +7,9 @@ import org.junit.Test;
|
|||
import com.baeldung.datetime.sql.TimeUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeUtilsUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenCurrentTime_thenNowIsReturned() {
|
||||
assertEquals(TimeUtils.getNow(), new Date());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void givenTimeAsString_whenPatternIsNotRespected_thenExceptionIsThrown() {
|
||||
TimeUtils.getTime("10 11 12");
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Intellij
|
||||
.idea/
|
||||
*.iml
|
||||
0.*
|
||||
|
||||
# Files generated by integration tests
|
||||
# *.txt
|
||||
/temp
|
|
@ -1,4 +1,15 @@
|
|||
## Core Java IO
|
||||
|
||||
This module contains articles about core Java input and output (IO)
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Create a File in a Specific Directory in Java](https://www.baeldung.com/java-create-file-in-directory)
|
||||
- [How to Read a Large File Efficiently with Java](https://www.baeldung.com/java-read-lines-large-file)
|
||||
- [Java – Write to File](https://www.baeldung.com/java-write-to-file)
|
||||
- [FileNotFoundException in Java](https://www.baeldung.com/java-filenotfound-exception)
|
||||
- [Delete the Contents of a File in Java](https://www.baeldung.com/java-delete-file-contents)
|
||||
- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files)
|
||||
- [Java – Append Data to a File](https://www.baeldung.com/java-append-to-file)
|
||||
- [How to Copy a File with Java](https://www.baeldung.com/java-copy-file)
|
||||
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-io)
|
||||
|
|
|
@ -16,57 +16,16 @@
|
|||
<dependencies>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.collections</groupId>
|
||||
<artifactId>collections-generic</artifactId>
|
||||
<version>${collections-generic.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${commons-math3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.decimal4j</groupId>
|
||||
<artifactId>decimal4j</artifactId>
|
||||
<version>${decimal4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.unix4j</groupId>
|
||||
<artifactId>unix4j-command</artifactId>
|
||||
<version>${unix4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.grep4j</groupId>
|
||||
<artifactId>grep4j</artifactId>
|
||||
<version>${grep4j.version}</version>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
<!-- marshalling -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
|
@ -78,12 +37,6 @@
|
|||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
|
@ -91,86 +44,6 @@
|
|||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>${moneta.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>${esapi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.messaging.mq</groupId>
|
||||
<artifactId>fscontext</artifactId>
|
||||
<version>${fscontext.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.codepoetics</groupId>
|
||||
<artifactId>protonpack</artifactId>
|
||||
<version>${protonpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>one.util</groupId>
|
||||
<artifactId>streamex</artifactId>
|
||||
<version>${streamex.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
<version>${vavr.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>${hsqldb.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.asynchttpclient/async-http-client -->
|
||||
<dependency>
|
||||
<groupId>org.asynchttpclient</groupId>
|
||||
<artifactId>async-http-client</artifactId>
|
||||
<version>${async-http-client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>${opencsv.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Mime Type Resolution Libraries -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
<version>${tika.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.jmimemagic</groupId>
|
||||
<artifactId>jmimemagic</artifactId>
|
||||
<version>${jmime-magic.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -182,22 +55,6 @@
|
|||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
<arguments>
|
||||
<argument>-Xmx300m</argument>
|
||||
<argument>-XX:+UseParallelGC</argument>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
|
@ -210,70 +67,9 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
<!-- <phase>integration-test</phase> -->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>org.openjdk.jmh.Main</argument>
|
||||
<argument>.*</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
|
||||
<!-- util -->
|
||||
<bouncycastle.version>1.55</bouncycastle.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<fscontext.version>4.6-b01</fscontext.version>
|
||||
<protonpack.version>1.13</protonpack.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
<opencsv.version>4.1</opencsv.version>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<esapi.version>2.1.0.1</esapi.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
<async-http-client.version>2.4.5</async-http-client.version>
|
||||
<!-- Mime Type Libraries -->
|
||||
<tika.version>1.18</tika.version>
|
||||
<jmime-magic.version>0.1.5</jmime-magic.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.files;
|
||||
package com.baeldung.listfiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.file;
|
||||
package com.baeldung.appendtofile;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -22,9 +22,7 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.util.StreamUtils;
|
||||
|
||||
public class FilesManualTest {
|
||||
public class AppendToFileManualTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package com.baeldung.util;
|
||||
package com.baeldung.appendtofile;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class StreamUtils {
|
||||
|
||||
public static String getStringFromInputStream(InputStream input) throws IOException {
|
|
@ -5,15 +5,27 @@ import org.junit.Test;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CreateFilesUnitTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void clean() {
|
||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
File file1 = new File(tempDirectory.getAbsolutePath() + "/testFile.txt");
|
||||
File file2 = new File(tempDirectory, "newFile.txt");
|
||||
File file3 = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile2.txt");
|
||||
file1.delete();
|
||||
file2.delete();
|
||||
file3.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnExistingDirectory_whenCreatingAFileWithAbsolutePath_thenFileIsCreated() throws IOException {
|
||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/myDirectory/testFile.txt");
|
||||
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/testFile.txt");
|
||||
|
||||
assertFalse(fileWithAbsolutePath.exists());
|
||||
|
||||
|
@ -25,7 +37,7 @@ public class CreateFilesUnitTest {
|
|||
@Test
|
||||
public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFileWithRelativePath_thenFileIsCreated() throws IOException {
|
||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt");
|
||||
File fileWithRelativePath = new File(tempDirectory, "newFile.txt");
|
||||
|
||||
assertFalse(fileWithRelativePath.exists());
|
||||
|
||||
|
@ -37,7 +49,7 @@ public class CreateFilesUnitTest {
|
|||
@Test
|
||||
public void whenCreatingAFileWithFileSeparator_thenFileIsCreated() throws IOException {
|
||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
File newFile = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile.txt");
|
||||
File newFile = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile2.txt");
|
||||
|
||||
assertFalse(newFile.exists());
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.file;
|
||||
package com.baeldung.deletecontents;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -20,8 +20,6 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.util.StreamUtils;
|
||||
|
||||
public class FilesClearDataUnitTest {
|
||||
|
||||
public static final String FILE_PATH = "src/test/resources/fileexample.txt";
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.deletecontents;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class StreamUtils {
|
||||
|
||||
public static String getStringFromInputStream(InputStream input) throws IOException {
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(input, writer, "UTF-8");
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.core.exceptions;
|
||||
package com.baeldung.filenotfoundexception;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.file;
|
||||
package com.baeldung.listfiles;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import java.util.Set;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.files.ListFiles;
|
||||
import com.baeldung.listfiles.ListFiles;
|
||||
|
||||
public class ListFilesUnitTest {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.java;
|
||||
package com.baeldung.readlargefile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -16,7 +16,7 @@ import com.google.common.base.Charsets;
|
|||
import com.google.common.io.Files;
|
||||
|
||||
@Ignore("need large file for testing")
|
||||
public class JavaIoUnitTest {
|
||||
public class ReadLargeFileUnitTest {
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
// tests - iterate lines in a file
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.writetofile;
|
||||
package com.baeldung.writetofile;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
@ -1 +0,0 @@
|
|||
Hello, World!
|
|
@ -12,3 +12,5 @@ This module contains articles about core Java input/output(IO) APIs.
|
|||
- [Quick Use of FilenameFilter](https://www.baeldung.com/java-filename-filter)
|
||||
- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader)
|
||||
- [Java Scanner](https://www.baeldung.com/java-scanner)
|
||||
- [Scanner nextLine() Method](https://www.baeldung.com/java-scanner-nextline)
|
||||
- [Java Scanner hasNext() vs. hasNextLine()](https://www.baeldung.com/java-scanner-hasnext-vs-hasnextline)
|
|
@ -14,6 +14,23 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.baeldung.scanner;
|
||||
package com.baeldung.scannernextline;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class JavaScannerUnitTest {
|
||||
public class ScannerNextLineUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenReadingLines_thenCorrect() {
|
|
@ -7,3 +7,11 @@ This module contains articles about core Java input/output(IO) conversions.
|
|||
- [Java – Convert File to InputStream](https://www.baeldung.com/convert-file-to-input-stream)
|
||||
- [Java – Byte Array to Writer](https://www.baeldung.com/java-convert-byte-array-to-writer)
|
||||
- [Java InputStream to Byte Array and ByteBuffer](https://www.baeldung.com/convert-input-stream-to-array-of-bytes)
|
||||
- [Java – String to Reader](https://www.baeldung.com/java-convert-string-to-reader)
|
||||
- [Java – Byte Array to Reader](https://www.baeldung.com/java-convert-byte-array-to-reader)
|
||||
- [Java – File to Reader](https://www.baeldung.com/java-convert-file-to-reader)
|
||||
- [Java – InputStream to Reader](https://www.baeldung.com/java-convert-inputstream-to-reader)
|
||||
- [Java – Reader to String](https://www.baeldung.com/java-convert-reader-to-string)
|
||||
- [Java – Write a Reader to File](https://www.baeldung.com/java-write-reader-to-file)
|
||||
- [Java – Reader to Byte Array](https://www.baeldung.com/java-convert-reader-to-byte-array)
|
||||
- [Java – Reader to InputStream](https://www.baeldung.com/java-convert-reader-to-inputstream)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.java.io;
|
||||
package com.baeldung.readertox;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.java.io;
|
||||
package com.baeldung.xtoreader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
|
@ -1,5 +0,0 @@
|
|||
0.*
|
||||
|
||||
# Files generated by integration tests
|
||||
# *.txt
|
||||
/temp
|
|
@ -1,6 +0,0 @@
|
|||
=========
|
||||
|
||||
## Core Java IO Files Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
- [How to Avoid the Java FileNotFoundException When Loading Resources](https://www.baeldung.com/java-classpath-resource-cannot-be-opened)
|
|
@ -1,132 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-io-files</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-io-files</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>${hsqldb.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-io-files</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
<arguments>
|
||||
<argument>-Xmx300m</argument>
|
||||
<argument>-XX:+UseParallelGC</argument>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- Build an executable JAR -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>${maven-jar-plugin.version}</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>com.baeldung.resource.MyResourceLoader</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
<!-- <phase>integration-test</phase> -->
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
<argument>-classpath</argument>
|
||||
<classpath />
|
||||
<argument>org.openjdk.jmh.Main</argument>
|
||||
<argument>.*</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<!-- Mime Type Libraries -->
|
||||
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,42 +0,0 @@
|
|||
package com.baeldung.resource;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MyResourceLoader {
|
||||
|
||||
private void loadFileWithReader() throws IOException {
|
||||
|
||||
try (FileReader fileReader = new FileReader("src/main/resources/input.txt");
|
||||
BufferedReader reader = new BufferedReader(fileReader)) {
|
||||
String contents = reader.lines()
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
System.out.println(contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadFileAsResource() throws IOException {
|
||||
|
||||
try (InputStream inputStream = getClass().getResourceAsStream("/input.txt");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String contents = reader.lines()
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
System.out.println(contents);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
MyResourceLoader resourceLoader = new MyResourceLoader();
|
||||
|
||||
resourceLoader.loadFileAsResource();
|
||||
resourceLoader.loadFileWithReader();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In lacus enim, scelerisque id sapien ut, semper euismod quam. Nunc ullamcorper semper blandit. Praesent quis quam mollis, iaculis lectus a, fringilla leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis vitae auctor mauris. Pellentesque eu pellentesque lorem, vel ultricies libero. Pellentesque vestibulum sagittis eros. In vestibulum lacus elit. Interdum et malesuada fames ac ante ipsum primis in faucibus.
|
||||
|
||||
Vivamus pharetra lacus fringilla nisl molestie eleifend. Donec et dolor non quam mattis mattis. Proin malesuada maximus elit id semper. Donec facilisis dolor ut feugiat auctor. Proin accumsan semper consectetur. Vivamus facilisis odio vel bibendum imperdiet. Sed rutrum nisi nec nisi interdum fringilla. Aliquam laoreet velit ullamcorper egestas ultrices. Aliquam ultricies sem sed orci interdum, eu porta purus malesuada. Sed accumsan, nunc ut maximus rhoncus, arcu ante pretium ex, non ultrices magna nisi et velit. Pellentesque tempor mi quis lacus consectetur, quis imperdiet enim efficitur. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
|
||||
|
||||
Nunc sed maximus erat. Aenean imperdiet finibus massa ac aliquam. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis dignissim cursus purus, eu tempus urna. Nunc sed mauris scelerisque, luctus eros ut, viverra nisi. Maecenas congue sed ligula in eleifend. Praesent nec dignissim enim, dictum efficitur massa. Nullam eros dui, rutrum quis aliquam accumsan, sollicitudin cursus eros. Phasellus euismod, lorem vitae vehicula ullamcorper, leo lorem vestibulum magna, vitae malesuada libero ipsum id lorem. Aenean finibus turpis facilisis tortor bibendum, vitae dignissim dolor dictum. Ut quis ornare nisi, non rutrum sapien.
|
||||
|
||||
Etiam placerat, est eget placerat imperdiet, neque urna tristique est, a dictum nisl dolor vitae leo. Vivamus porttitor mi vitae volutpat ultrices. Quisque at ante porta mauris ultricies iaculis. Phasellus iaculis sollicitudin urna nec facilisis. Suspendisse dapibus vulputate scelerisque. Fusce felis diam, eleifend in tristique in, malesuada a purus. Suspendisse euismod ipsum sed urna imperdiet, quis venenatis lacus dapibus. Maecenas vitae est vel sem fringilla ornare at ut mi. Quisque porta, nulla at rutrum fringilla, mi ligula egestas libero, ac convallis elit diam et sapien. Vestibulum purus tortor, ornare ut enim sed, mattis lobortis erat. Maecenas ac ante tincidunt, euismod mauris a, fermentum diam. Nullam arcu est, consequat sed enim in, bibendum aliquet velit. Donec bibendum magna ac augue sagittis vehicula. Curabitur nec mauris eu augue bibendum volutpat. Fusce fringilla varius fringilla.
|
||||
|
||||
Aliquam faucibus massa non orci accumsan, porta consectetur diam vulputate. Nullam nec erat mollis, imperdiet libero nec, tincidunt neque. Aenean varius purus nec est auctor, sed vulputate libero varius. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vel neque elit. Donec vulputate fermentum nulla, ut aliquam neque tempor in. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec vel venenatis est. Suspendisse luctus elit quis dui dapibus, id sodales dolor cursus. Curabitur ut vehicula dui. Fusce aliquet est et ante feugiat, et tempus ex congue. Nunc eget dapibus leo. Nunc eu accumsan diam. Suspendisse risus eros, rutrum et volutpat in, consequat in nulla. Suspendisse id felis a orci accumsan iaculis.
|
||||
|
||||
Duis tincidunt diam eget tortor aliquet sodales. Etiam sodales purus ac urna mollis, et cursus enim porttitor. Nulla viverra ligula nunc, ornare condimentum felis posuere sed. Fusce aliquet pretium sagittis. Sed ac mi elementum massa dictum ornare. Integer quis dapibus lectus. Curabitur in rhoncus justo, et vulputate justo. Integer eget efficitur felis.
|
||||
|
||||
Sed finibus vel tortor ac egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vestibulum nulla mi, blandit efficitur sapien fermentum eu. Integer sed turpis eros. Phasellus sed aliquam ligula. Etiam dictum quam in dapibus mattis. Donec et tristique quam. Pellentesque gravida luctus dolor, eu ornare sapien. Donec justo ante, lacinia non sem et, ultricies dignissim nibh. Vivamus eu nisl et magna pulvinar efficitur. Sed at vehicula lectus, sit amet luctus sem. Morbi vehicula sapien nisi, nec sagittis orci vestibulum et.
|
||||
|
||||
Praesent non finibus diam. Quisque sit amet nisl vitae augue lobortis commodo. Morbi ullamcorper, tortor id ornare maximus, erat ipsum ullamcorper ipsum, in imperdiet diam sem vel erat. Sed pellentesque quis ex sed volutpat. Vestibulum volutpat diam ac dignissim sollicitudin. Praesent at luctus ex, at volutpat dui. Nunc nulla dui, lobortis et pharetra quis, efficitur in turpis. Donec sodales auctor purus id mollis. Sed auctor eu erat eget bibendum. Mauris tincidunt ornare neque id consequat. Suspendisse non massa ante. Quisque velit enim, rhoncus at erat eget, scelerisque placerat elit. Donec finibus luctus dolor. In sed eleifend lorem. Sed tempor ullamcorper lorem nec tristique. Fusce nec volutpat neque, id elementum est.
|
||||
|
||||
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum mattis elementum tellus, vitae maximus nulla eleifend ut. Vestibulum eu nibh vulputate, posuere felis eget, aliquet ex. Nullam leo ex, lacinia a ante ac, accumsan efficitur ligula. Vestibulum ornare gravida tempus. Proin rhoncus felis sit amet dolor commodo facilisis. Integer aliquet, diam sed pharetra feugiat, sem massa mollis orci, eget pretium libero nunc at quam. Ut rhoncus quam vitae massa hendrerit, ornare condimentum odio varius. Donec odio sapien, tristique eget libero ac, interdum facilisis odio. Phasellus nec mauris vel dolor semper mattis et quis ligula. Donec nec porttitor nunc. Integer maximus quam vitae sem gravida, ut commodo ex porttitor.
|
||||
|
||||
Sed cursus nisi turpis, vel laoreet massa blandit ut. Cras posuere velit nulla, nec pellentesque ipsum dignissim eget. Donec pharetra, ex et commodo viverra, leo dolor dapibus tellus, vel dignissim est sem ac lectus. Quisque a arcu dapibus, aliquet magna sed, rhoncus neque. Integer suscipit, nulla ac varius lacinia, orci metus scelerisque neque, a laoreet nibh risus vitae dolor. Pellentesque felis metus, pulvinar vel cursus id, ultrices non purus. Donec mi lectus, faucibus sit amet nunc at, sagittis pretium lectus. Fusce nec purus arcu. Mauris neque neque, blandit eget mi at, auctor tempus orci. Mauris sapien lorem, luctus nec tellus non, porttitor aliquam dui.
|
||||
|
||||
Mauris non ex risus. Aliquam imperdiet in eros eget placerat. Sed congue sed sapien porta sollicitudin. Phasellus tempor hendrerit metus vitae tincidunt. Suspendisse congue nisi sed augue dapibus, at pretium ante mollis. Cras non posuere nulla. Proin malesuada finibus magna vel iaculis. Cras in dapibus lorem. Pellentesque volutpat dolor sit amet magna tincidunt mollis. Nunc et lectus sodales, accumsan est vitae, ornare augue. Maecenas malesuada arcu leo, eget blandit lectus porttitor et. Nam aliquam sapien sit amet purus consequat lobortis. Aenean varius, augue porta dignissim efficitur, felis velit dapibus leo, tincidunt ultricies magna felis id ligula. Duis hendrerit, lectus eu elementum euismod, elit lectus consequat mi, sit amet egestas justo massa ut urna. Proin eleifend interdum ultrices.
|
||||
|
||||
Donec lacinia orci pharetra ornare tincidunt. Nulla facilisi. Maecenas malesuada dui ac elit sagittis tincidunt id dictum dolor. Quisque lobortis purus ac metus volutpat viverra. Proin finibus sapien ut odio semper consectetur. Sed gravida luctus egestas. Mauris pretium volutpat elit, at commodo arcu sagittis nec. Ut condimentum fringilla urna ac dignissim. Cras aliquam metus pulvinar, pulvinar nibh at, placerat arcu. Nulla ornare tortor sed lectus mollis, vitae fringilla tellus egestas. Vivamus efficitur tincidunt sapien, sed finibus mi congue eu. Nullam magna velit, lacinia vitae ligula eget, molestie consectetur felis. Suspendisse varius turpis orci, ac laoreet arcu accumsan sed. Fusce quis fermentum lacus, nec varius libero. Pellentesque ac odio ut justo lobortis elementum sit amet vehicula lorem. Nulla interdum nulla eget mi tristique, vitae egestas nunc egestas.
|
||||
|
||||
Curabitur commodo libero eu elit tincidunt, quis placerat risus vehicula. Vestibulum vehicula id nunc iaculis fermentum. Aenean semper, tellus ac semper rutrum, justo lorem feugiat leo, quis vulputate neque dui non ligula. Etiam egestas, enim eget tempor porta, nunc est tristique ante, vel suscipit massa lorem vel diam. Donec faucibus ante id turpis rhoncus congue. Nullam laoreet, diam efficitur scelerisque consequat, ligula leo ultrices est, non fermentum elit mauris ut dolor. Morbi non porttitor lorem. Sed volutpat sapien et lorem porttitor, ultricies ultricies tellus congue. Mauris sodales, tortor nec sagittis finibus, dui odio aliquet nibh, in luctus sapien massa eu risus. Nulla in est sed ante molestie vehicula vel nec lectus. Fusce maximus a quam eget aliquam. Vivamus pulvinar quis nisi a maximus. Proin cursus lacus sapien, et hendrerit elit pretium a. Donec tellus lectus, consectetur id dolor a, luctus rutrum libero. Suspendisse auctor scelerisque dui, nec pellentesque felis viverra nec. Cras elit ex, varius sed pulvinar sed, suscipit ultrices lacus.
|
||||
|
||||
Vivamus eu luctus lectus. Maecenas congue magna orci, quis semper nulla blandit vel. Phasellus dignissim risus placerat lacinia sagittis. Praesent at gravida nisi, at pulvinar diam. Nulla egestas lectus sed felis facilisis egestas. Curabitur posuere gravida urna eu vestibulum. Pellentesque at dolor gravida, placerat quam sit amet, fermentum ligula. Morbi fringilla, mi eget mollis dictum, neque dolor ullamcorper leo, a rutrum libero ipsum eget orci. Curabitur consectetur iaculis vestibulum. Suspendisse ultricies ligula et neque lacinia luctus. Sed dignissim neque id eros sollicitudin pellentesque.
|
||||
|
||||
Donec et magna quis lectus pharetra finibus a fringilla sapien. Phasellus accumsan, erat eu sodales cursus, tortor elit dapibus risus, ut ornare neque arcu in tellus. Nam ac vehicula diam, at aliquam nisl. Cras in sem eget nisi ultrices rutrum sit amet eu velit. Sed molestie tellus eget ante scelerisque, sit amet pulvinar neque fringilla. Nunc volutpat facilisis egestas. Cras sodales dui ac massa egestas, in mattis leo rhoncus. Pellentesque vitae urna vehicula ipsum sodales suscipit. Sed commodo tempus fringilla.
|
||||
|
||||
Etiam egestas elit vitae mi maximus fringilla quis eget libero. Fusce finibus ultrices tellus at molestie. Pellentesque posuere blandit elementum. Etiam eu erat eu urna hendrerit euismod. Nulla quis lectus rhoncus, ultricies urna eget, pretium neque. Cras sit amet ipsum sit amet purus rutrum ultricies nec vitae tortor. Sed tempor dapibus augue in pulvinar. Ut pretium sapien in malesuada accumsan. Donec eget ultrices erat, ut efficitur ligula. Sed posuere mauris est, nec convallis ipsum tempus non.
|
||||
|
||||
Duis a ullamcorper ante. Quisque eu ultricies metus, at aliquet odio. Nullam tempus molestie augue ut varius. Fusce purus eros, dictum nec finibus sed, sodales et diam. Suspendisse sed mi purus. Donec eleifend ipsum diam, nec fringilla enim laoreet non. Phasellus condimentum, magna sit amet porttitor suscipit, arcu risus lobortis dolor, ac fringilla nibh nisl vel purus. Phasellus facilisis posuere orci sit amet tempus. Nam nec enim maximus, rhoncus felis a, rutrum diam.
|
||||
|
||||
Suspendisse potenti. Donec vel tempor neque. In aliquet nulla in eleifend bibendum. Sed sapien sem, finibus in sodales vitae, euismod in sem. Phasellus nec elit a erat pulvinar semper. Aliquam luctus nisl in libero molestie aliquam. Nunc ac ornare felis. Ut non mauris ut ipsum rhoncus pretium. Curabitur tristique lacus a sagittis aliquam. Morbi vel volutpat tellus. Maecenas volutpat, lacus sed tempus imperdiet, eros tellus volutpat nisi, a egestas augue nulla quis arcu. In sollicitudin imperdiet efficitur. Suspendisse viverra aliquet nisi, congue ultrices arcu hendrerit in.
|
||||
|
||||
Maecenas vitae vestibulum nunc. Nullam semper faucibus tincidunt. Etiam sed hendrerit risus. Proin gravida, urna nec tincidunt tempus, nulla sapien porttitor nibh, porttitor lobortis nunc quam et tortor. Praesent ut varius lacus, ut hendrerit enim. Ut nec turpis ac felis imperdiet bibendum. Phasellus porttitor enim odio, et vehicula mi convallis vel. Quisque porta scelerisque sagittis. Praesent dignissim sagittis vulputate. Aenean non justo ac est volutpat bibendum. Aliquam mattis, sapien dapibus pellentesque semper, velit urna malesuada diam, nec varius nibh eros at erat. Proin leo ante, ultricies id velit ut, faucibus porta nibh. Sed nec fermentum urna, sed mollis leo. Aliquam erat volutpat.
|
||||
|
||||
Donec condimentum, urna sed hendrerit vestibulum, ante nibh lacinia dui, in tincidunt odio sem eget orci. In hac habitasse platea dictumst. Mauris id ex id ante tempus finibus eu sagittis erat. Quisque interdum urna risus, vel varius nibh euismod non. Nulla eget pellentesque quam. Aliquam vestibulum ac tortor non lobortis. Sed vitae erat sed libero dignissim dictum nec in turpis. Vivamus id ornare elit, ut facilisis lectus. Morbi dictum purus eget ipsum dignissim porttitor. Sed at vehicula purus, nec rhoncus quam. Nunc a nisl quis arcu blandit fermentum vel quis odio. Vivamus rhoncus, sapien sed lacinia hendrerit, velit urna fermentum dolor, id feugiat magna ligula sed urna. Proin euismod efficitur libero, eget porttitor lacus tempus quis. Duis tincidunt quis est a laoreet. Nam sit amet tristique nisl, sit amet mattis mi.
|
||||
|
||||
Aenean id dictum nulla, sed laoreet magna. Morbi consectetur in turpis at aliquam. Maecenas rutrum feugiat metus, at ullamcorper augue fermentum ut. Vivamus in magna pretium nibh dictum rhoncus luctus at orci. In hac habitasse platea dictumst. Fusce convallis, nulla nec hendrerit suscipit, ipsum diam lobortis sem, vitae elementum lectus erat sit amet magna. Quisque sollicitudin fringilla purus, ac molestie justo congue vitae. Nulla sapien leo, ullamcorper ac tellus in, cursus rhoncus enim. Suspendisse rutrum magna non ex elementum elementum id vitae enim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse ornare libero eu molestie pulvinar. Phasellus faucibus, magna eget rutrum porta, lorem turpis blandit lectus, eu viverra massa risus et ex.
|
||||
|
||||
Ut consectetur eros lacus, ac ullamcorper lacus mattis a. Cras congue justo ut erat interdum, et scelerisque nisi malesuada. Quisque sed sapien sollicitudin purus tincidunt finibus vestibulum vel dolor. Cras iaculis bibendum erat, a dictum urna viverra et. Integer non neque vulputate, tincidunt purus nec, rutrum arcu. Aliquam nec magna non sem semper laoreet quis at quam. Mauris dui lectus, convallis eu efficitur at, facilisis nec lorem. Cras felis sem, egestas ac rutrum vel, mollis et ex. Aenean semper egestas libero, nec commodo mi blandit efficitur. Duis nec quam in massa dignissim sagittis vel vitae leo. Nam molestie hendrerit auctor.
|
||||
|
||||
Sed suscipit egestas tellus sed cursus. Donec vel massa sit amet dui condimentum accumsan. Phasellus libero eros, lobortis a nisi id, porttitor maximus lectus. Praesent consectetur diam urna, id viverra turpis elementum in. Vivamus vitae pretium justo, nec tempor felis. Vivamus volutpat ultricies magna. Suspendisse vulputate lectus ac orci volutpat ullamcorper. Nulla eu leo pretium, commodo arcu accumsan, tempor nisl. Fusce sit amet tellus a ipsum vehicula laoreet sed vitae mauris. Duis porttitor massa mattis nibh placerat consequat. Fusce rutrum commodo tortor eget pellentesque. Suspendisse tempor enim libero, consequat dictum nibh dictum varius. Pellentesque feugiat sit amet urna sed facilisis. Curabitur a sagittis augue.
|
|
@ -1,13 +0,0 @@
|
|||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
|
@ -3,21 +3,14 @@
|
|||
This module contains articles about core Java input and output (IO)
|
||||
|
||||
### Relevant Articles:
|
||||
- [How to Read a Large File Efficiently with Java](http://www.baeldung.com/java-read-lines-large-file)
|
||||
- [Java – Write to File](http://www.baeldung.com/java-write-to-file)
|
||||
- [Java – Directory Size](http://www.baeldung.com/java-folder-size)
|
||||
- [File Size in Java](http://www.baeldung.com/java-file-size)
|
||||
- [How to Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
||||
- [Java – Append Data to a File](http://www.baeldung.com/java-append-to-file)
|
||||
- [FileNotFoundException in Java](http://www.baeldung.com/java-filenotfound-exception)
|
||||
- [How to Read a File in Java](http://www.baeldung.com/reading-file-in-java)
|
||||
- [Zipping and Unzipping in Java](http://www.baeldung.com/java-compress-and-uncompress)
|
||||
- [How to Read a File in Java](https://www.baeldung.com/reading-file-in-java)
|
||||
- [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist)
|
||||
- [Java – Directory Size](https://www.baeldung.com/java-folder-size)
|
||||
- [File Size in Java](https://www.baeldung.com/java-file-size)
|
||||
- [Zipping and Unzipping in Java](https://www.baeldung.com/java-compress-and-uncompress)
|
||||
- [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array)
|
||||
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
|
||||
- [Getting a File’s Mime Type in Java](http://www.baeldung.com/java-file-mime-type)
|
||||
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
|
||||
- [How to Get the File Extension of a File in Java](https://www.baeldung.com/java-file-extension)
|
||||
- [Getting a File’s Mime Type in Java](https://www.baeldung.com/java-file-mime-type)
|
||||
- [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv)
|
||||
- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files)
|
||||
- [How to Avoid the Java FileNotFoundException When Loading Resources](https://www.baeldung.com/java-classpath-resource-cannot-be-opened)
|
||||
- [[More -->]](/core-java-modules/core-java-io-2)
|
||||
|
|
|
@ -140,12 +140,10 @@
|
|||
</profiles>
|
||||
|
||||
<properties>
|
||||
|
||||
<!-- util -->
|
||||
<opencsv.version>4.1</opencsv.version>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package com.baeldung.stream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
public class FileCopy {
|
||||
|
||||
public static void copyFileUsingStream(File source, File dest) throws IOException {
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
is = new FileInputStream(source);
|
||||
os = new FileOutputStream(dest);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, length);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
|
||||
public static void copyFileUsingChannel(File source, File dest) throws IOException {
|
||||
FileChannel sourceChannel = null;
|
||||
FileChannel destChannel = null;
|
||||
sourceChannel = new FileInputStream(source).getChannel();
|
||||
destChannel = new FileOutputStream(dest).getChannel();
|
||||
destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
|
||||
sourceChannel.close();
|
||||
destChannel.close();
|
||||
}
|
||||
|
||||
public static void copyFileUsingApacheCommonsIO(File source, File dest) throws IOException {
|
||||
FileUtils.copyFile(source, dest);
|
||||
}
|
||||
|
||||
public static void copyFileUsingJavaFiles(File source, File dest) throws IOException {
|
||||
Files.copy(source.toPath(), dest.toPath());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,453 +0,0 @@
|
|||
#
|
||||
# OWASP Enterprise Security API (ESAPI) Properties file -- PRODUCTION Version
|
||||
#
|
||||
# This file is part of the Open Web Application Security Project (OWASP)
|
||||
# Enterprise Security API (ESAPI) project. For details, please see
|
||||
# http://www.owasp.org/index.php/ESAPI.
|
||||
#
|
||||
# Copyright (c) 2008,2009 - The OWASP Foundation
|
||||
#
|
||||
# DISCUSS: This may cause a major backwards compatibility issue, etc. but
|
||||
# from a name space perspective, we probably should have prefaced
|
||||
# all the property names with ESAPI or at least OWASP. Otherwise
|
||||
# there could be problems is someone loads this properties file into
|
||||
# the System properties. We could also put this file into the
|
||||
# esapi.jar file (perhaps as a ResourceBundle) and then allow an external
|
||||
# ESAPI properties be defined that would overwrite these defaults.
|
||||
# That keeps the application's properties relatively simple as usually
|
||||
# they will only want to override a few properties. If looks like we
|
||||
# already support multiple override levels of this in the
|
||||
# DefaultSecurityConfiguration class, but I'm suggesting placing the
|
||||
# defaults in the esapi.jar itself. That way, if the jar is signed,
|
||||
# we could detect if those properties had been tampered with. (The
|
||||
# code to check the jar signatures is pretty simple... maybe 70-90 LOC,
|
||||
# but off course there is an execution penalty (similar to the way
|
||||
# that the separate sunjce.jar used to be when a class from it was
|
||||
# first loaded). Thoughts?
|
||||
###############################################################################
|
||||
#
|
||||
# WARNING: Operating system protection should be used to lock down the .esapi
|
||||
# resources directory and all the files inside and all the directories all the
|
||||
# way up to the root directory of the file system. Note that if you are using
|
||||
# file-based implementations, that some files may need to be read-write as they
|
||||
# get updated dynamically.
|
||||
#
|
||||
# Before using, be sure to update the MasterKey and MasterSalt as described below.
|
||||
# N.B.: If you had stored data that you have previously encrypted with ESAPI 1.4,
|
||||
# you *must* FIRST decrypt it using ESAPI 1.4 and then (if so desired)
|
||||
# re-encrypt it with ESAPI 2.0. If you fail to do this, you will NOT be
|
||||
# able to decrypt your data with ESAPI 2.0.
|
||||
#
|
||||
# YOU HAVE BEEN WARNED!!! More details are in the ESAPI 2.0 Release Notes.
|
||||
#
|
||||
#===========================================================================
|
||||
# ESAPI Configuration
|
||||
#
|
||||
# If true, then print all the ESAPI properties set here when they are loaded.
|
||||
# If false, they are not printed. Useful to reduce output when running JUnit tests.
|
||||
# If you need to troubleshoot a properties related problem, turning this on may help.
|
||||
# This is 'false' in the src/test/resources/.esapi version. It is 'true' by
|
||||
# default for reasons of backward compatibility with earlier ESAPI versions.
|
||||
ESAPI.printProperties=true
|
||||
|
||||
# ESAPI is designed to be easily extensible. You can use the reference implementation
|
||||
# or implement your own providers to take advantage of your enterprise's security
|
||||
# infrastructure. The functions in ESAPI are referenced using the ESAPI locator, like:
|
||||
#
|
||||
# String ciphertext =
|
||||
# ESAPI.encryptor().encrypt("Secret message"); // Deprecated in 2.0
|
||||
# CipherText cipherText =
|
||||
# ESAPI.encryptor().encrypt(new PlainText("Secret message")); // Preferred
|
||||
#
|
||||
# Below you can specify the classname for the provider that you wish to use in your
|
||||
# application. The only requirement is that it implement the appropriate ESAPI interface.
|
||||
# This allows you to switch security implementations in the future without rewriting the
|
||||
# entire application.
|
||||
#
|
||||
# ExperimentalAccessController requires ESAPI-AccessControlPolicy.xml in .esapi directory
|
||||
ESAPI.AccessControl=org.owasp.esapi.reference.DefaultAccessController
|
||||
# FileBasedAuthenticator requires users.txt file in .esapi directory
|
||||
ESAPI.Authenticator=org.owasp.esapi.reference.FileBasedAuthenticator
|
||||
ESAPI.Encoder=org.owasp.esapi.reference.DefaultEncoder
|
||||
ESAPI.Encryptor=org.owasp.esapi.reference.crypto.JavaEncryptor
|
||||
|
||||
ESAPI.Executor=org.owasp.esapi.reference.DefaultExecutor
|
||||
ESAPI.HTTPUtilities=org.owasp.esapi.reference.DefaultHTTPUtilities
|
||||
ESAPI.IntrusionDetector=org.owasp.esapi.reference.DefaultIntrusionDetector
|
||||
# Log4JFactory Requires log4j.xml or log4j.properties in classpath - http://www.laliluna.de/log4j-tutorial.html
|
||||
ESAPI.Logger=org.owasp.esapi.reference.Log4JLogFactory
|
||||
#ESAPI.Logger=org.owasp.esapi.reference.JavaLogFactory
|
||||
ESAPI.Randomizer=org.owasp.esapi.reference.DefaultRandomizer
|
||||
ESAPI.Validator=org.owasp.esapi.reference.DefaultValidator
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Authenticator
|
||||
#
|
||||
Authenticator.AllowedLoginAttempts=3
|
||||
Authenticator.MaxOldPasswordHashes=13
|
||||
Authenticator.UsernameParameterName=username
|
||||
Authenticator.PasswordParameterName=password
|
||||
# RememberTokenDuration (in days)
|
||||
Authenticator.RememberTokenDuration=14
|
||||
# Session Timeouts (in minutes)
|
||||
Authenticator.IdleTimeoutDuration=20
|
||||
Authenticator.AbsoluteTimeoutDuration=120
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Encoder
|
||||
#
|
||||
# ESAPI canonicalizes input before validation to prevent bypassing filters with encoded attacks.
|
||||
# Failure to canonicalize input is a very common mistake when implementing validation schemes.
|
||||
# Canonicalization is automatic when using the ESAPI Validator, but you can also use the
|
||||
# following code to canonicalize data.
|
||||
#
|
||||
# ESAPI.Encoder().canonicalize( "%22hello world"" );
|
||||
#
|
||||
# Multiple encoding is when a single encoding format is applied multiple times. Allowing
|
||||
# multiple encoding is strongly discouraged.
|
||||
Encoder.AllowMultipleEncoding=false
|
||||
|
||||
# Mixed encoding is when multiple different encoding formats are applied, or when
|
||||
# multiple formats are nested. Allowing multiple encoding is strongly discouraged.
|
||||
Encoder.AllowMixedEncoding=false
|
||||
|
||||
# The default list of codecs to apply when canonicalizing untrusted data. The list should include the codecs
|
||||
# for all downstream interpreters or decoders. For example, if the data is likely to end up in a URL, HTML, or
|
||||
# inside JavaScript, then the list of codecs below is appropriate. The order of the list is not terribly important.
|
||||
Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Encryption
|
||||
#
|
||||
# The ESAPI Encryptor provides basic cryptographic functions with a simplified API.
|
||||
# To get started, generate a new key using java -classpath esapi.jar org.owasp.esapi.reference.crypto.JavaEncryptor
|
||||
# There is not currently any support for key rotation, so be careful when changing your key and salt as it
|
||||
# will invalidate all signed, encrypted, and hashed data.
|
||||
#
|
||||
# WARNING: Not all combinations of algorithms and key lengths are supported.
|
||||
# If you choose to use a key length greater than 128, you MUST download the
|
||||
# unlimited strength policy files and install in the lib directory of your JRE/JDK.
|
||||
# See http://java.sun.com/javase/downloads/index.jsp for more information.
|
||||
#
|
||||
# Backward compatibility with ESAPI Java 1.4 is supported by the two deprecated API
|
||||
# methods, Encryptor.encrypt(String) and Encryptor.decrypt(String). However, whenever
|
||||
# possible, these methods should be avoided as they use ECB cipher mode, which in almost
|
||||
# all circumstances a poor choice because of it's weakness. CBC cipher mode is the default
|
||||
# for the new Encryptor encrypt / decrypt methods for ESAPI Java 2.0. In general, you
|
||||
# should only use this compatibility setting if you have persistent data encrypted with
|
||||
# version 1.4 and even then, you should ONLY set this compatibility mode UNTIL
|
||||
# you have decrypted all of your old encrypted data and then re-encrypted it with
|
||||
# ESAPI 2.0 using CBC mode. If you have some reason to mix the deprecated 1.4 mode
|
||||
# with the new 2.0 methods, make sure that you use the same cipher algorithm for both
|
||||
# (256-bit AES was the default for 1.4; 128-bit is the default for 2.0; see below for
|
||||
# more details.) Otherwise, you will have to use the new 2.0 encrypt / decrypt methods
|
||||
# where you can specify a SecretKey. (Note that if you are using the 256-bit AES,
|
||||
# that requires downloading the special jurisdiction policy files mentioned above.)
|
||||
#
|
||||
# ***** IMPORTANT: Do NOT forget to replace these with your own values! *****
|
||||
# To calculate these values, you can run:
|
||||
# java -classpath esapi.jar org.owasp.esapi.reference.crypto.JavaEncryptor
|
||||
#
|
||||
Encryptor.MasterKey=tzfztf56ftv
|
||||
Encryptor.MasterSalt=123456ztrewq
|
||||
|
||||
# Provides the default JCE provider that ESAPI will "prefer" for its symmetric
|
||||
# encryption and hashing. (That is it will look to this provider first, but it
|
||||
# will defer to other providers if the requested algorithm is not implemented
|
||||
# by this provider.) If left unset, ESAPI will just use your Java VM's current
|
||||
# preferred JCE provider, which is generally set in the file
|
||||
# "$JAVA_HOME/jre/lib/security/java.security".
|
||||
#
|
||||
# The main intent of this is to allow ESAPI symmetric encryption to be
|
||||
# used with a FIPS 140-2 compliant crypto-module. For details, see the section
|
||||
# "Using ESAPI Symmetric Encryption with FIPS 140-2 Cryptographic Modules" in
|
||||
# the ESAPI 2.0 Symmetric Encryption User Guide, at:
|
||||
# http://owasp-esapi-java.googlecode.com/svn/trunk/documentation/esapi4java-core-2.0-symmetric-crypto-user-guide.html
|
||||
# However, this property also allows you to easily use an alternate JCE provider
|
||||
# such as "Bouncy Castle" without having to make changes to "java.security".
|
||||
# See Javadoc for SecurityProviderLoader for further details. If you wish to use
|
||||
# a provider that is not known to SecurityProviderLoader, you may specify the
|
||||
# fully-qualified class name of the JCE provider class that implements
|
||||
# java.security.Provider. If the name contains a '.', this is interpreted as
|
||||
# a fully-qualified class name that implements java.security.Provider.
|
||||
#
|
||||
# NOTE: Setting this property has the side-effect of changing it in your application
|
||||
# as well, so if you are using JCE in your application directly rather than
|
||||
# through ESAPI (you wouldn't do that, would you? ;-), it will change the
|
||||
# preferred JCE provider there as well.
|
||||
#
|
||||
# Default: Keeps the JCE provider set to whatever JVM sets it to.
|
||||
Encryptor.PreferredJCEProvider=
|
||||
|
||||
# AES is the most widely used and strongest encryption algorithm. This
|
||||
# should agree with your Encryptor.CipherTransformation property.
|
||||
# By default, ESAPI Java 1.4 uses "PBEWithMD5AndDES" and which is
|
||||
# very weak. It is essentially a password-based encryption key, hashed
|
||||
# with MD5 around 1K times and then encrypted with the weak DES algorithm
|
||||
# (56-bits) using ECB mode and an unspecified padding (it is
|
||||
# JCE provider specific, but most likely "NoPadding"). However, 2.0 uses
|
||||
# "AES/CBC/PKCSPadding". If you want to change these, change them here.
|
||||
# Warning: This property does not control the default reference implementation for
|
||||
# ESAPI 2.0 using JavaEncryptor. Also, this property will be dropped
|
||||
# in the future.
|
||||
# @deprecated
|
||||
Encryptor.EncryptionAlgorithm=AES
|
||||
# For ESAPI Java 2.0 - New encrypt / decrypt methods use this.
|
||||
Encryptor.CipherTransformation=AES/CBC/PKCS5Padding
|
||||
|
||||
# Applies to ESAPI 2.0 and later only!
|
||||
# Comma-separated list of cipher modes that provide *BOTH*
|
||||
# confidentiality *AND* message authenticity. (NIST refers to such cipher
|
||||
# modes as "combined modes" so that's what we shall call them.) If any of these
|
||||
# cipher modes are used then no MAC is calculated and stored
|
||||
# in the CipherText upon encryption. Likewise, if one of these
|
||||
# cipher modes is used with decryption, no attempt will be made
|
||||
# to validate the MAC contained in the CipherText object regardless
|
||||
# of whether it contains one or not. Since the expectation is that
|
||||
# these cipher modes support support message authenticity already,
|
||||
# injecting a MAC in the CipherText object would be at best redundant.
|
||||
#
|
||||
# Note that as of JDK 1.5, the SunJCE provider does not support *any*
|
||||
# of these cipher modes. Of these listed, only GCM and CCM are currently
|
||||
# NIST approved. YMMV for other JCE providers. E.g., Bouncy Castle supports
|
||||
# GCM and CCM with "NoPadding" mode, but not with "PKCS5Padding" or other
|
||||
# padding modes.
|
||||
Encryptor.cipher_modes.combined_modes=GCM,CCM,IAPM,EAX,OCB,CWC
|
||||
|
||||
# Applies to ESAPI 2.0 and later only!
|
||||
# Additional cipher modes allowed for ESAPI 2.0 encryption. These
|
||||
# cipher modes are in _addition_ to those specified by the property
|
||||
# 'Encryptor.cipher_modes.combined_modes'.
|
||||
# Note: We will add support for streaming modes like CFB & OFB once
|
||||
# we add support for 'specified' to the property 'Encryptor.ChooseIVMethod'
|
||||
# (probably in ESAPI 2.1).
|
||||
# DISCUSS: Better name?
|
||||
Encryptor.cipher_modes.additional_allowed=CBC
|
||||
|
||||
# 128-bit is almost always sufficient and appears to be more resistant to
|
||||
# related key attacks than is 256-bit AES. Use '_' to use default key size
|
||||
# for cipher algorithms (where it makes sense because the algorithm supports
|
||||
# a variable key size). Key length must agree to what's provided as the
|
||||
# cipher transformation, otherwise this will be ignored after logging a
|
||||
# warning.
|
||||
#
|
||||
# NOTE: This is what applies BOTH ESAPI 1.4 and 2.0. See warning above about mixing!
|
||||
Encryptor.EncryptionKeyLength=128
|
||||
|
||||
# Because 2.0 uses CBC mode by default, it requires an initialization vector (IV).
|
||||
# (All cipher modes except ECB require an IV.) There are two choices: we can either
|
||||
# use a fixed IV known to both parties or allow ESAPI to choose a random IV. While
|
||||
# the IV does not need to be hidden from adversaries, it is important that the
|
||||
# adversary not be allowed to choose it. Also, random IVs are generally much more
|
||||
# secure than fixed IVs. (In fact, it is essential that feed-back cipher modes
|
||||
# such as CFB and OFB use a different IV for each encryption with a given key so
|
||||
# in such cases, random IVs are much preferred. By default, ESAPI 2.0 uses random
|
||||
# IVs. If you wish to use 'fixed' IVs, set 'Encryptor.ChooseIVMethod=fixed' and
|
||||
# uncomment the Encryptor.fixedIV.
|
||||
#
|
||||
# Valid values: random|fixed|specified 'specified' not yet implemented; planned for 2.1
|
||||
Encryptor.ChooseIVMethod=random
|
||||
# If you choose to use a fixed IV, then you must place a fixed IV here that
|
||||
# is known to all others who are sharing your secret key. The format should
|
||||
# be a hex string that is the same length as the cipher block size for the
|
||||
# cipher algorithm that you are using. The following is an *example* for AES
|
||||
# from an AES test vector for AES-128/CBC as described in:
|
||||
# NIST Special Publication 800-38A (2001 Edition)
|
||||
# "Recommendation for Block Cipher Modes of Operation".
|
||||
# (Note that the block size for AES is 16 bytes == 128 bits.)
|
||||
#
|
||||
Encryptor.fixedIV=0x000102030405060708090a0b0c0d0e0f
|
||||
|
||||
# Whether or not CipherText should use a message authentication code (MAC) with it.
|
||||
# This prevents an adversary from altering the IV as well as allowing a more
|
||||
# fool-proof way of determining the decryption failed because of an incorrect
|
||||
# key being supplied. This refers to the "separate" MAC calculated and stored
|
||||
# in CipherText, not part of any MAC that is calculated as a result of a
|
||||
# "combined mode" cipher mode.
|
||||
#
|
||||
# If you are using ESAPI with a FIPS 140-2 cryptographic module, you *must* also
|
||||
# set this property to false.
|
||||
Encryptor.CipherText.useMAC=true
|
||||
|
||||
# Whether or not the PlainText object may be overwritten and then marked
|
||||
# eligible for garbage collection. If not set, this is still treated as 'true'.
|
||||
Encryptor.PlainText.overwrite=true
|
||||
|
||||
# Do not use DES except in a legacy situations. 56-bit is way too small key size.
|
||||
#Encryptor.EncryptionKeyLength=56
|
||||
#Encryptor.EncryptionAlgorithm=DES
|
||||
|
||||
# TripleDES is considered strong enough for most purposes.
|
||||
# Note: There is also a 112-bit version of DESede. Using the 168-bit version
|
||||
# requires downloading the special jurisdiction policy from Sun.
|
||||
#Encryptor.EncryptionKeyLength=168
|
||||
#Encryptor.EncryptionAlgorithm=DESede
|
||||
|
||||
Encryptor.HashAlgorithm=SHA-512
|
||||
Encryptor.HashIterations=1024
|
||||
Encryptor.DigitalSignatureAlgorithm=SHA1withDSA
|
||||
Encryptor.DigitalSignatureKeyLength=1024
|
||||
Encryptor.RandomAlgorithm=SHA1PRNG
|
||||
Encryptor.CharacterEncoding=UTF-8
|
||||
|
||||
# This is the Pseudo Random Function (PRF) that ESAPI's Key Derivation Function
|
||||
# (KDF) normally uses. Note this is *only* the PRF used for ESAPI's KDF and
|
||||
# *not* what is used for ESAPI's MAC. (Currently, HmacSHA1 is always used for
|
||||
# the MAC, mostly to keep the overall size at a minimum.)
|
||||
#
|
||||
# Currently supported choices for JDK 1.5 and 1.6 are:
|
||||
# HmacSHA1 (160 bits), HmacSHA256 (256 bits), HmacSHA384 (384 bits), and
|
||||
# HmacSHA512 (512 bits).
|
||||
# Note that HmacMD5 is *not* supported for the PRF used by the KDF even though
|
||||
# the JDKs support it. See the ESAPI 2.0 Symmetric Encryption User Guide
|
||||
# further details.
|
||||
Encryptor.KDF.PRF=HmacSHA256
|
||||
#===========================================================================
|
||||
# ESAPI HttpUtilties
|
||||
#
|
||||
# The HttpUtilities provide basic protections to HTTP requests and responses. Primarily these methods
|
||||
# protect against malicious data from attackers, such as unprintable characters, escaped characters,
|
||||
# and other simple attacks. The HttpUtilities also provides utility methods for dealing with cookies,
|
||||
# headers, and CSRF tokens.
|
||||
#
|
||||
# Default file upload location (remember to escape backslashes with \\)
|
||||
HttpUtilities.UploadDir=C:\\ESAPI\\testUpload
|
||||
HttpUtilities.UploadTempDir=C:\\temp
|
||||
# Force flags on cookies, if you use HttpUtilities to set cookies
|
||||
HttpUtilities.ForceHttpOnlySession=false
|
||||
HttpUtilities.ForceSecureSession=false
|
||||
HttpUtilities.ForceHttpOnlyCookies=true
|
||||
HttpUtilities.ForceSecureCookies=true
|
||||
# Maximum size of HTTP headers
|
||||
HttpUtilities.MaxHeaderSize=4096
|
||||
# File upload configuration
|
||||
HttpUtilities.ApprovedUploadExtensions=.zip,.pdf,.doc,.docx,.ppt,.pptx,.tar,.gz,.tgz,.rar,.war,.jar,.ear,.xls,.rtf,.properties,.java,.class,.txt,.xml,.jsp,.jsf,.exe,.dll
|
||||
HttpUtilities.MaxUploadFileBytes=500000000
|
||||
# Using UTF-8 throughout your stack is highly recommended. That includes your database driver,
|
||||
# container, and any other technologies you may be using. Failure to do this may expose you
|
||||
# to Unicode transcoding injection attacks. Use of UTF-8 does not hinder internationalization.
|
||||
HttpUtilities.ResponseContentType=text/html; charset=UTF-8
|
||||
# This is the name of the cookie used to represent the HTTP session
|
||||
# Typically this will be the default "JSESSIONID"
|
||||
HttpUtilities.HttpSessionIdName=JSESSIONID
|
||||
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Executor
|
||||
# CHECKME - Not sure what this is used for, but surely it should be made OS independent.
|
||||
Executor.WorkingDirectory=C:\\Windows\\Temp
|
||||
Executor.ApprovedExecutables=C:\\Windows\\System32\\cmd.exe,C:\\Windows\\System32\\runas.exe
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Logging
|
||||
# Set the application name if these logs are combined with other applications
|
||||
Logger.ApplicationName=ExampleApplication
|
||||
# If you use an HTML log viewer that does not properly HTML escape log data, you can set LogEncodingRequired to true
|
||||
Logger.LogEncodingRequired=false
|
||||
# Determines whether ESAPI should log the application name. This might be clutter in some single-server/single-app environments.
|
||||
Logger.LogApplicationName=true
|
||||
# Determines whether ESAPI should log the server IP and port. This might be clutter in some single-server environments.
|
||||
Logger.LogServerIP=true
|
||||
# LogFileName, the name of the logging file. Provide a full directory path (e.g., C:\\ESAPI\\ESAPI_logging_file) if you
|
||||
# want to place it in a specific directory.
|
||||
Logger.LogFileName=ESAPI_logging_file
|
||||
# MaxLogFileSize, the max size (in bytes) of a single log file before it cuts over to a new one (default is 10,000,000)
|
||||
Logger.MaxLogFileSize=10000000
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Intrusion Detection
|
||||
#
|
||||
# Each event has a base to which .count, .interval, and .action are added
|
||||
# The IntrusionException will fire if we receive "count" events within "interval" seconds
|
||||
# The IntrusionDetector is configurable to take the following actions: log, logout, and disable
|
||||
# (multiple actions separated by commas are allowed e.g. event.test.actions=log,disable
|
||||
#
|
||||
# Custom Events
|
||||
# Names must start with "event." as the base
|
||||
# Use IntrusionDetector.addEvent( "test" ) in your code to trigger "event.test" here
|
||||
# You can also disable intrusion detection completely by changing
|
||||
# the following parameter to true
|
||||
#
|
||||
IntrusionDetector.Disable=false
|
||||
#
|
||||
IntrusionDetector.event.test.count=2
|
||||
IntrusionDetector.event.test.interval=10
|
||||
IntrusionDetector.event.test.actions=disable,log
|
||||
|
||||
# Exception Events
|
||||
# All EnterpriseSecurityExceptions are registered automatically
|
||||
# Call IntrusionDetector.getInstance().addException(e) for Exceptions that do not extend EnterpriseSecurityException
|
||||
# Use the fully qualified classname of the exception as the base
|
||||
|
||||
# any intrusion is an attack
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntrusionException.count=1
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntrusionException.interval=1
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntrusionException.actions=log,disable,logout
|
||||
|
||||
# for test purposes
|
||||
# CHECKME: Shouldn't there be something in the property name itself that designates
|
||||
# that these are for testing???
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntegrityException.count=10
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntegrityException.interval=5
|
||||
IntrusionDetector.org.owasp.esapi.errors.IntegrityException.actions=log,disable,logout
|
||||
|
||||
# rapid validation errors indicate scans or attacks in progress
|
||||
# org.owasp.esapi.errors.ValidationException.count=10
|
||||
# org.owasp.esapi.errors.ValidationException.interval=10
|
||||
# org.owasp.esapi.errors.ValidationException.actions=log,logout
|
||||
|
||||
# sessions jumping between hosts indicates session hijacking
|
||||
IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.count=2
|
||||
IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.interval=10
|
||||
IntrusionDetector.org.owasp.esapi.errors.AuthenticationHostException.actions=log,logout
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# ESAPI Validation
|
||||
#
|
||||
# The ESAPI Validator works on regular expressions with defined names. You can define names
|
||||
# either here, or you may define application specific patterns in a separate file defined below.
|
||||
# This allows enterprises to specify both organizational standards as well as application specific
|
||||
# validation rules.
|
||||
#
|
||||
Validator.ConfigurationFile=validation.properties
|
||||
|
||||
# Validators used by ESAPI
|
||||
Validator.AccountName=^[a-zA-Z0-9]{3,20}$
|
||||
Validator.SystemCommand=^[a-zA-Z\\-\\/]{1,64}$
|
||||
Validator.RoleName=^[a-z]{1,20}$
|
||||
|
||||
#the word TEST below should be changed to your application
|
||||
#name - only relative URL's are supported
|
||||
Validator.Redirect=^\\/test.*$
|
||||
|
||||
# Global HTTP Validation Rules
|
||||
# Values with Base64 encoded data (e.g. encrypted state) will need at least [a-zA-Z0-9\/+=]
|
||||
Validator.HTTPScheme=^(http|https)$
|
||||
Validator.HTTPServerName=^[a-zA-Z0-9_.\\-]*$
|
||||
Validator.HTTPParameterName=^[a-zA-Z0-9_]{1,32}$
|
||||
Validator.HTTPParameterValue=^[a-zA-Z0-9.\\-\\/+=@_ ]*$
|
||||
Validator.HTTPCookieName=^[a-zA-Z0-9\\-_]{1,32}$
|
||||
Validator.HTTPCookieValue=^[a-zA-Z0-9\\-\\/+=_ ]*$
|
||||
Validator.HTTPHeaderName=^[a-zA-Z0-9\\-_]{1,32}$
|
||||
Validator.HTTPHeaderValue=^[a-zA-Z0-9()\\-=\\*\\.\\?;,+\\/:&_ ]*$
|
||||
Validator.HTTPContextPath=^\\/?[a-zA-Z0-9.\\-\\/_]*$
|
||||
Validator.HTTPServletPath=^[a-zA-Z0-9.\\-\\/_]*$
|
||||
Validator.HTTPPath=^[a-zA-Z0-9.\\-_]*$
|
||||
Validator.HTTPQueryString=^[a-zA-Z0-9()\\-=\\*\\.\\?;,+\\/:&_ %]*$
|
||||
Validator.HTTPURI=^[a-zA-Z0-9()\\-=\\*\\.\\?;,+\\/:&_ ]*$
|
||||
Validator.HTTPURL=^.*$
|
||||
Validator.HTTPJSESSIONID=^[A-Z0-9]{10,30}$
|
||||
|
||||
# Validation of file related input
|
||||
Validator.FileName=^[a-zA-Z0-9!@#$%^&{}\\[\\]()_+\\-=,.~'` ]{1,255}$
|
||||
Validator.DirectoryName=^[a-zA-Z0-9:/\\\\!@#$%^&{}\\[\\]()_+\\-=,.~'` ]{1,255}$
|
||||
|
||||
# Validation of dates. Controls whether or not 'lenient' dates are accepted.
|
||||
# See DataFormat.setLenient(boolean flag) for further details.
|
||||
Validator.AcceptLenientDates=false
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">
|
||||
|
||||
<!-- JDO tutorial "unit" -->
|
||||
<persistence-unit name="Tutorial">
|
||||
<exclude-unlisted-classes/>
|
||||
<properties>
|
||||
<property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
|
||||
<property name="javax.jdo.option.ConnectionURL" value="jdbc:h2:mem:mypersistence"/>
|
||||
<property name="javax.jdo.option.ConnectionDriverName" value="org.h2.Driver"/>
|
||||
<property name="javax.jdo.option.ConnectionUserName" value="sa"/>
|
||||
<property name="javax.jdo.option.ConnectionPassword" value=""/>
|
||||
<property name="datanucleus.schema.autoCreateAll" value="true"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
|
@ -1 +0,0 @@
|
|||
com.baeldung.javac.SampleJavacPlugin
|
|
@ -1,3 +0,0 @@
|
|||
1|IND|India
|
||||
2|MY|Malaysia
|
||||
3|AU|Australia
|
|
|
@ -1,6 +0,0 @@
|
|||
dataSourceClassName=//TBD
|
||||
dataSource.user=//TBD
|
||||
dataSource.password=//TBD
|
||||
dataSource.databaseName=//TBD
|
||||
dataSource.portNumber=//TBD
|
||||
dataSource.serverName=//TBD
|
|
@ -1,15 +0,0 @@
|
|||
var first = {
|
||||
name: "Whiskey",
|
||||
age: 5
|
||||
};
|
||||
|
||||
var second = {
|
||||
volume: 100
|
||||
};
|
||||
|
||||
Object.bindProperties(first, second);
|
||||
|
||||
print(first.volume);
|
||||
|
||||
second.volume = 1000;
|
||||
print(first.volume);
|
|
@ -1 +0,0 @@
|
|||
print(__FILE__, __LINE__, __DIR__);
|
|
@ -1,19 +0,0 @@
|
|||
var math = {
|
||||
increment: function (num) {
|
||||
return ++num;
|
||||
},
|
||||
|
||||
failFunc: function () {
|
||||
try {
|
||||
throw "BOOM";
|
||||
} catch (e if typeof e === 'string') {
|
||||
print("String thrown: " + e);
|
||||
}
|
||||
catch (e) {
|
||||
print("this shouldn't happen!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
math;
|
|
@ -1,11 +0,0 @@
|
|||
var demo = {
|
||||
__noSuchProperty__: function (propName) {
|
||||
print("Accessed non-existing property: " + propName);
|
||||
},
|
||||
|
||||
__noSuchMethod__: function (methodName) {
|
||||
print("Invoked non-existing method: " + methodName);
|
||||
}
|
||||
};
|
||||
|
||||
demo;
|
|
@ -1 +0,0 @@
|
|||
function increment(num) ++num;
|
|
@ -1,2 +0,0 @@
|
|||
print(" hello world".trimLeft());
|
||||
print("hello world ".trimRight());
|
|
@ -1,9 +0,0 @@
|
|||
function arrays(arr) {
|
||||
|
||||
var javaIntArray = Java.to(arr, "int[]");
|
||||
print(javaIntArray[0]);
|
||||
print(javaIntArray[1]);
|
||||
print(javaIntArray[2]);
|
||||
}
|
||||
|
||||
arrays([100, "1654", true]);
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.filesystem.jndi.test;
|
||||
package com.baeldung.filesystem.jndi;
|
||||
|
||||
import com.baeldung.filesystem.jndi.LookupFSJNDI;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.mimetype;
|
||||
package com.baeldung.mimetype;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.java.io;
|
||||
package com.baeldung.readfile;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java8;
|
||||
package com.baeldung.size;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class JavaFileSizeUnitTest {
|
|||
@Before
|
||||
public void init() {
|
||||
final String separator = File.separator;
|
||||
filePath = String.join(separator, new String[] { "src", "test", "resources", "testFolder", "sample_file_1.in" });
|
||||
filePath = String.join(separator, new String[] { "src", "test", "resources", "size", "sample_file_1.in" });
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java8;
|
||||
package com.baeldung.size;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class JavaFolderSizeUnitTest {
|
|||
@Before
|
||||
public void init() {
|
||||
final String separator = File.separator;
|
||||
path = String.format("src%stest%sresources%stestFolder", separator, separator, separator);
|
||||
path = String.format("src%stest%sresources%ssize", separator, separator, separator);
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,52 +0,0 @@
|
|||
package com.baeldung.stream;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileCopyUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingStream_thenCopyFile() throws IOException {
|
||||
final File src = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "src" + File.separator + "test_stream.txt");
|
||||
final File dest = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "dest" + File.separator + "test_stream.txt");
|
||||
FileCopy.copyFileUsingStream(src, dest);
|
||||
|
||||
assertTrue(dest.exists());
|
||||
dest.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFiles_thenCopyFile() throws IOException {
|
||||
final File src = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "src" + File.separator + "test_files.txt");
|
||||
final File dest = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "dest" + File.separator + "test_files.txt");
|
||||
FileCopy.copyFileUsingJavaFiles(src, dest);
|
||||
|
||||
assertTrue(dest.exists());
|
||||
dest.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingChannel_thenCopyFile() throws IOException {
|
||||
final File src = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "src" + File.separator + "test_channel.txt");
|
||||
final File dest = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "dest" + File.separator + "test_channel.txt");
|
||||
FileCopy.copyFileUsingChannel(src, dest);
|
||||
|
||||
assertTrue(dest.exists());
|
||||
dest.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingApache_thenCopyFile() throws IOException {
|
||||
final File src = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "src" + File.separator + "test_apache.txt");
|
||||
final File dest = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "copyTest" + File.separator + "dest" + File.separator + "test_apache.txt");
|
||||
FileCopy.copyFileUsingApacheCommonsIO(src, dest);
|
||||
|
||||
assertTrue(dest.exists());
|
||||
dest.delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package org.baeldung.java.io;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JavaXToByteArrayUnitTest {
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
// tests - X to Byte Array
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
|
@ -1,2 +0,0 @@
|
|||
files will be copied here and then deleted
|
||||
remove `file.delete()` to see the files here
|
|
@ -1 +0,0 @@
|
|||
apache
|
|
@ -1 +0,0 @@
|
|||
channel
|
|
@ -1 +0,0 @@
|
|||
files
|
|
@ -1 +0,0 @@
|
|||
stream
|
|
@ -1 +0,0 @@
|
|||
Hello World
|
|
@ -1,24 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BufferedReaderExample {
|
||||
|
||||
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
|
||||
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
|
||||
|
||||
while (br.ready()) {
|
||||
result.add(br.readLine());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FileReaderExample {
|
||||
|
||||
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
|
||||
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
try (FileReader f = new FileReader(filename)) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (f.ready()) {
|
||||
char c = (char) f.read();
|
||||
if (c == '\n') {
|
||||
result.add(sb.toString());
|
||||
sb = new StringBuffer();
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
result.add(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilesReadLinesExample {
|
||||
|
||||
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
|
||||
|
||||
List<String> result = Files.readAllLines(Paths.get(filename));
|
||||
|
||||
return (ArrayList<String>) result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ScannerIntExample {
|
||||
|
||||
protected static ArrayList<Integer> generateArrayListFromFile(String filename) throws IOException {
|
||||
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
|
||||
try (Scanner s = new Scanner(new FileReader(filename))) {
|
||||
|
||||
while (s.hasNext()) {
|
||||
result.add(s.nextInt());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ScannerStringExample {
|
||||
|
||||
protected static ArrayList<String> generateArrayListFromFile(String filename) throws IOException {
|
||||
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
try (Scanner s = new Scanner(new FileReader(filename))) {
|
||||
|
||||
while (s.hasNext()) {
|
||||
result.add(s.nextLine());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BufferedReaderUnitTest {
|
||||
|
||||
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
|
||||
|
||||
@Test
|
||||
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
|
||||
List<String> lines = BufferedReaderExample.generateArrayListFromFile(TEXT_FILENAME);
|
||||
assertTrue("File does not has 2 lines", lines.size() == 2);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileReaderUnitTest {
|
||||
|
||||
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
|
||||
|
||||
@Test
|
||||
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
|
||||
List<String> lines = FileReaderExample.generateArrayListFromFile(TEXT_FILENAME);
|
||||
assertTrue("File does not has 2 lines", lines.size() == 2);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FilesReadAllLinesUnitTest {
|
||||
|
||||
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
|
||||
|
||||
@Test
|
||||
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
|
||||
List<String> lines = FilesReadLinesExample.generateArrayListFromFile(TEXT_FILENAME);
|
||||
assertTrue("File does not has 2 lines", lines.size() == 2);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ScannerIntUnitTest {
|
||||
|
||||
protected static final String NUMBER_FILENAME = "src/test/resources/sampleNumberFile.txt";
|
||||
|
||||
@Test
|
||||
public void whenParsingExistingTextFile_thenGetIntArrayList() throws IOException {
|
||||
List<Integer> numbers = ScannerIntExample.generateArrayListFromFile(NUMBER_FILENAME);
|
||||
assertTrue("File does not has 2 lines", numbers.size() == 2);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.baeldung.fileparser;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ScannerStringUnitTest {
|
||||
|
||||
protected static final String TEXT_FILENAME = "src/test/resources/sampleTextFile.txt";
|
||||
|
||||
@Test
|
||||
public void whenParsingExistingTextFile_thenGetArrayList() throws IOException {
|
||||
List<String> lines = ScannerStringExample.generateArrayListFromFile(TEXT_FILENAME);
|
||||
assertTrue("File does not has 2 lines", lines.size() == 2);
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
111
|
||||
222
|
|
@ -1,2 +0,0 @@
|
|||
Hello
|
||||
World
|
|
@ -17,8 +17,8 @@
|
|||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>jnosql-diana</module>
|
||||
<module>jnosql-artemis</module>
|
||||
<module>jnosql-diana</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -18,28 +18,34 @@
|
|||
<module>apache-cayenne</module>
|
||||
<module>core-java-persistence</module>
|
||||
<module>deltaspike</module>
|
||||
<module>elasticsearch</module>
|
||||
<module>flyway</module>
|
||||
<module>hbase</module>
|
||||
<module>hibernate5</module>
|
||||
<module>hibernate-ogm</module>
|
||||
<module>hibernate-mapping</module>
|
||||
<module>hibernate5-2</module>
|
||||
<module>hibernate-mapping</module> <!-- long running -->
|
||||
<module>hibernate-ogm</module>
|
||||
<module>influxdb</module>
|
||||
<module>java-cassandra</module>
|
||||
<module>java-cockroachdb</module>
|
||||
<module>java-jdbi</module>
|
||||
<module>java-jpa</module>
|
||||
<module>java-jpa-2</module>
|
||||
<module>java-mongodb</module>
|
||||
<module>persistence-libraries</module>
|
||||
<module>jnosql</module>
|
||||
<module>java-jpa</module> <!-- long running -->
|
||||
<module>java-jpa-2</module> <!-- long running -->
|
||||
<module>java-mongodb</module> <!-- long running -->
|
||||
<module>jnosql</module> <!-- long running -->
|
||||
<module>jpa-hibernate-cascade-type</module>
|
||||
<module>liquibase</module>
|
||||
<module>orientdb</module>
|
||||
<module>persistence-libraries</module>
|
||||
<module>querydsl</module>
|
||||
<module>r2dbc</module>
|
||||
<module>redis</module>
|
||||
<!-- <module>sirix</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
|
||||
<module>solr</module>
|
||||
<module>spring-boot-persistence-h2</module>
|
||||
<module>spring-boot-jdbi</module>
|
||||
<module>spring-boot-mysql</module>
|
||||
<module>spring-boot-persistence</module>
|
||||
<module>spring-boot-persistence-h2</module>
|
||||
<module>spring-boot-persistence-mongodb</module>
|
||||
<module>spring-data-cassandra</module>
|
||||
<module>spring-data-cassandra-reactive</module>
|
||||
|
@ -50,19 +56,20 @@
|
|||
<module>spring-data-gemfire</module>
|
||||
<module>spring-data-geode</module>
|
||||
<module>spring-data-jpa</module>
|
||||
<module>spring-data-jpa-2</module>
|
||||
<module>spring-data-jpa-3</module>
|
||||
<module>spring-data-jpa-4</module>
|
||||
<module>spring-data-keyvalue</module>
|
||||
<module>spring-data-mongodb</module> <!-- long -->
|
||||
<module>spring-data-mongodb</module>
|
||||
<module>spring-data-neo4j</module>
|
||||
<module>spring-data-redis</module>
|
||||
<module>spring-data-solr</module>
|
||||
<module>spring-hibernate-3</module>
|
||||
<module>spring-hibernate-5</module>
|
||||
<module>spring-hibernate-5</module> <!-- long running -->
|
||||
<module>spring-hibernate4</module>
|
||||
<module>spring-jpa</module>
|
||||
<!-- <module>spring-mybatis</module> --> <!-- needs fixing in BAEL-9021 -->
|
||||
<module>spring-persistence-simple</module>
|
||||
<module>jpa-hibernate-cascade-type</module>
|
||||
<module>r2dbc</module>
|
||||
<module>spring-boot-jdbi</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -9,7 +9,3 @@
|
|||
- [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable)
|
||||
- [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete)
|
||||
- [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs)
|
||||
- [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update)
|
||||
- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush)
|
||||
- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries)
|
||||
- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue