This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InputStream inputStream = null; | |
byte[] dataChunk = new byte[1024]; | |
try { | |
inputStream = new FileInputStream("test.txt"); | |
while (inputStream.read(dataChunk) != -1) { | |
//Perform operations on data... | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] dataChunk = new byte[1024]; | |
try (InputStream inputStream = new FileInputStream("test.txt")) { | |
while (inputStream.read(dataChunk) != -1) { | |
//Perform operations on data... | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String path = "tmp/documents"; | |
String fileName = "test.txt"; | |
File targetFile = new File(path, fileName); | |
InputStream inputStream = new FileInputStream(targetFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getStringFromStream(InputStream inputStream) throws IOException { | |
StringBuilder textBuilder = new StringBuilder(); | |
try (Reader reader = new BufferedReader(new InputStreamReader(inputStream))) { | |
int c = 0; | |
while ((c = reader.read()) != -1) { | |
textBuilder.append((char) c); | |
} | |
} | |
return textBuilder.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getStringFromStream(InputStream inputStream) throws IOException { | |
try (final Reader reader = new InputStreamReader(inputStream)) { | |
return CharStreams.toString(reader); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getStringFromStream(InputStream inputStream) throws IOException { | |
return IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
public Client saveNewClient(ClientDto clientDto) { | |
Client client = new Client(); | |
client.setName(clientDto.getName()); | |
client.setEmail(clientDto.getEmail()); | |
Client newClient = clientRepository.save(client); | |
return newClient; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
public void updateClientsName(String oldName, String newName) { | |
Client managedClient = clientRepository.findByName(oldName); | |
managedClient.setName(newName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class ClientsService { | |
private final ClientRepository clientRepository; | |
@Autowired | |
public ClientsService(ClientRepository clientRepository) { | |
this.clientRepository = clientRepository; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
public void deleteClientWithName(String name) { | |
Client managedClient = clientRepository.findByName(name); | |
clientRepository.delete(managedClient); | |
} |