전체 글
-
Java IO <7 - Writer>언어/자바 2023. 12. 25. 23:30
막연하게만 사용하던 I/O를 조금 더 이해해보고자 작성한 글입니다. 기본적으로 I/O는 O/S 레벨에서 이루어지고 byte를 다룬다는 것을 생각야해합니다. 자바 I/O 관련 마지막 글입니다 Writer Reader 클래스와 비슷하게 OutputStream을 String기반으로 사용할 수 있도록 하는 클래스이다. Writer = OutputStream + String 핸들링 1.FileWriter FileWriter를 사용하면 기존에 String을 byte[]로 변경해서 write작업을 수행하던 것을 하지않고 곧 바로 String을 사용해서 write를 할 수 있다. FileOutputStream public static void main(String[] args) throws IOException { F..
-
Java I/O <6 - Reader>통계언어/자바 2023. 12. 25. 23:25
막연하게만 사용하던 I/O를 조금 더 이해해보고자 작성한 글입니다. 기본적으로 I/O는 O/S 레벨에서 이루어지고 byte를 다룬다는 것을 생각야해합니다. Reader byte를 다루는 InputStream과 달리 Reader 클래스는 String을 다룰 때 사용되는 클래스이다. Reader클래스들은 InputStream을 내부에서 사용하거나 랩핑하여 사용한다. Reader = InputStream + String 핸들링 1. FileReader 영문을 입력할 때와 한글을 읽을 때를 각각 살펴보자. // test.txt this is a test sentence 한글 테스트 입니다. public static void main(String[] args) throws IOException { FileInpu..
-
Java I/O <5 - Buffered Stream>언어/자바 2023. 12. 25. 23:19
막연하게만 사용하던 I/O를 조금 더 이해해보고자 작성한 글입니다. 기본적으로 I/O는 O/S 레벨에서 이루어지고 byte를 다룬다는 것을 생각야해합니다. Buffered I/O Stream 앞에서 다루었던 I/O Stream들을 보다 효율적으로 다루기 위한 방법이다. 버퍼를 사용할 때와 안할 때의 차이를 왜 효율적인지 생각해보자. 동기식 I/O의 동작 방식 핵심은 파일이나 네트워크를 다루는 I/O는 CPU연산에 비해 엄청나게 느리기 때문에 적게 할수록 효율적이다는 것이다. 위 그림을 보면 1. InputStream은 매번 read()가 호출될 때마다 운영체제 혹은 디스크 레벨까지 접근을 하게 된다. 하지만 2번 BufferedInputStream 같은 경우에는 일단 디스크에서 버퍼 크기만큼의 데이터를 ..
-
Java I/O <4 - Network Stream>언어/자바 2023. 12. 25. 23:16
막연하게만 사용하던 I/O를 조금 더 이해해보고자 작성한 글입니다. 기본적으로 I/O는 O/S 레벨에서 이루어지고 byte를 다룬다는 것을 생각야해합니다. 네트워크를 왜 I/O로 분류하는가를 이해해보자. Socket과 I/O Stream 쓰레드를 사용하지 않고, socket에서 제공하는 Input/Output Stream을 사용해서 간단하게 메세지를 console에서 확인해보자. 1. 클라이언트에서 서버로 메세지를 보내보자 우선 원하는 포트를 지정해서 응답을 기다리는 서버를 만든다. 서버에 도착한 stream을 console에 출력해보자. // server public static void main(String[] args) { ServerSocket serverSocket = new ServerSock..
-
Java I/O <3 - FileStream>언어/자바 2023. 12. 25. 23:10
막연하게만 사용하던 I/O를 조금 더 이해해보고자 작성한 글입니다. 기본적으로 I/O는 O/S 레벨에서 이루어지고 byte를 다룬다는 것을 생각야해합니다. FileOutputStream 앞에서 다루었던 System클래스 속의 stream들은 콘솔을 기반으로 I/O를 수행했다면, 이번에 다루는 FileStream들은 파일을 기반으로 I/O를 수행한다. 1. 파일 쓰기 - 덮어쓰기 FileOutputStream 클래스에 전달된 경로에 파일이 없는 경우, 파일이 생성되고, 있는 경우는 해당 경로의 파일을 이용한다. public static void main(String[] args) throws IOException { FileOutputStream fileOutputStream = new FileOutput..
-
mongodb의 @Indexed 가 작동하지 않을 때프레임워크/Spring Boot 2023. 12. 24. 16:41
Entity에 @Indexed 어노테이션이 작동하지 않는 이슈를 해결하는 과정입니다. 아래는 Spring에서 선언한 Entity입니다. productId에 @Indexed(unique = true) 를 적용했음에도 DuplecateKeyError가 발생하지 않았습니다 @Document(collection="products") public class ProductEntity { @Id private String id; @Version private Integer version; @Indexed(unique = true) private int productId; 확인해보니 mongodb에 인덱스가 설정되지 있지 않았습니다 공식문서를 확인해보면 3.0 버전부터 의도하지 않은 impact를 방지하기 위해 명시적..
-
Junit5 에서 Junit4로 변경하기프레임워크/Spring Boot 2023. 12. 24. 14:44
1. 의존성 변경 스프링에서 junit 테스트를 실행하기 위해서는 아래와 같은 의존성을 추가해서 사용합니다. testImplementation 'org.springframework.boot:spring-boot-starter-test' 위 의존성은 Junit5를 기준으로 작동하게 되어있기 때문에 Junit4를 사용하고 싶으면 수정이 필요합니다. spring-boot-starter-test는 여러가지 패키지들을 조합해서 사용하는데, 대표 적으로 Junit5와 관련된 패키지는 아래와 같습니다. junit-jupiter junit-platform-commons 따라서 Junit4를 사용하고 싶다면 위의 패키지들을 제외하고, 추가로 Junit4를 의존성에 추가해주면 사용가능합니다. testImplementati..
-
24년 기준 수정해야되는 부분책/스프링으로 하는 마이크로서비스 구축 2023. 12. 23. 19:27
따라하기 종류의 책들은 시간이 지나면서 버전 때문에 문제가 생겨서 선호하지 않지만 이 책 구성이 마음에 들어서 차근차근 해보고 있습니다. 혹시나 이 책으로 공부하려는 다른 분들에게 도움이 될까하여 기록으로 남겨봅니다. (시작 부분의 내용이 이 글의 가장 아래쪽에 위치하고 있습니다.) Chapter06 - 영속성 추가 m1 관련 이슈가 있어서 docker-compose.yml을 아래와 같이 변경하였습니다. version: "2.1" services: product: build: microservices/product-service mem_limit: 350m environment: - SPRING_PROFILES_ACTIVE=docker depends_on: - mongodb recommendation: ..