Skip to content

Commit 29f35ea

Browse files
committed
Fix comments
1 parent 46fb64b commit 29f35ea

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public final class Messages {
8787
public static final String ERROR_OCCURRED_DURING_OBJECT_STORE_HEALTH_CHECKING_FOR_INSTANCE = "Error occurred during object store health checking for instance: \"{0}\"";
8888
public static final String ERROR_OCCURRED_WHILE_CHECKING_DATABASE_INSTANCE_0 = "Error occurred while checking database instance: \"{0}\"";
8989
public static final String INVALID_MULTIPART_FILE = "The provided multipart file cannot be empty";
90-
public static final String INVALID_YAML_FILE = "The provided {0} file is invalid! The file format must be either yaml or mtaext";
90+
public static final String THE_PROVIDED_0_FILE_IS_INVALID = "The provided {0} file is invalid! The file format must be either yaml or mtaext";
9191
public static final String UNSUPPORTED_FILE_FORMAT = "Unsupported file format! \"{0}\" detected";
9292

9393
// Warning messages

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/FileMimeTypeValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ private void validateYamlFile(InputStream uploadedFileInputStream, String filena
5757
try {
5858
yaml.load(uploadedFileInputStream);
5959
} catch (YAMLException e) {
60-
throw new IllegalArgumentException(MessageFormat.format(Messages.INVALID_YAML_FILE, filename), e);
60+
throw new IllegalArgumentException(MessageFormat.format(Messages.THE_PROVIDED_0_FILE_IS_INVALID, filename), e);
6161
}
6262
}
6363

6464
private void validateTextFileExtension(String filename) {
6565
String fileExtension = FilenameUtils.getExtension(filename);
6666

6767
if (!(YAML_FILE_EXTENSION.equals(fileExtension) || EXTENSION_DESCRIPTOR_FILE_EXTENSION.equals(fileExtension))) {
68-
throw new IllegalArgumentException(MessageFormat.format(Messages.INVALID_YAML_FILE, filename));
68+
throw new IllegalArgumentException(MessageFormat.format(Messages.THE_PROVIDED_0_FILE_IS_INVALID, filename));
6969
}
7070
}
7171
}

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/ValidateDeployParametersStep.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

33
import java.io.IOException;
4+
import java.io.InputStream;
45
import java.math.BigInteger;
56
import java.text.MessageFormat;
67
import java.util.ArrayList;
@@ -21,7 +22,6 @@
2122
import org.cloudfoundry.multiapps.controller.persistence.services.FileStorageException;
2223
import org.cloudfoundry.multiapps.controller.process.Messages;
2324
import org.cloudfoundry.multiapps.controller.process.stream.ArchiveStreamWithName;
24-
import org.cloudfoundry.multiapps.controller.process.stream.LazyArchiveInputStream;
2525
import org.cloudfoundry.multiapps.controller.process.util.FileSweeper;
2626
import org.cloudfoundry.multiapps.controller.process.util.MergedArchiveStreamCreator;
2727
import org.cloudfoundry.multiapps.controller.process.util.PriorityCallable;
@@ -185,22 +185,22 @@ private void mergeArchive(ProcessContext context, List<FileEntry> archivePartEnt
185185
archivePartEntries.size(), archiveSize);
186186
FileEntry uploadedArchive = persistArchive(archiveStreamWithName, context, archiveSize);
187187
context.setVariable(Variables.APP_ARCHIVE_ID, uploadedArchive.getId());
188-
validateMergedArchive(archiveStreamWithName);
188+
validateMergedArchive(uploadedArchive);
189189
getStepLogger().infoWithoutProgressMessage(MessageFormat.format(Messages.ARCHIVE_WITH_ID_0_AND_NAME_1_WAS_STORED,
190190
uploadedArchive.getId(),
191191
archiveStreamWithName.getArchiveName()));
192-
} catch (IOException e) {
193-
throw new SLException(e);
194192
} finally {
195193
IOUtils.closeQuietly(archiveStreamWithName.getArchiveStream());
196194
}
197195
}
198196

199-
private void validateMergedArchive(ArchiveStreamWithName archiveStreamWithName) throws IOException {
200-
LazyArchiveInputStream lazyArchiveInputStream = (LazyArchiveInputStream) archiveStreamWithName.getArchiveStream();
201-
fileMimeTypeValidator.validateInputStreamMimeType(lazyArchiveInputStream.getCurrentInputStream(),
202-
archiveStreamWithName.getArchiveName());
203-
lazyArchiveInputStream.close();
197+
private void validateMergedArchive(FileEntry fileEntry) {
198+
try (InputStream fileInputStream = fileService.openInputStream(fileEntry.getSpace(), fileEntry.getId())) {
199+
fileMimeTypeValidator.validateInputStreamMimeType(fileInputStream,
200+
fileEntry.getName());
201+
} catch (FileStorageException | IOException e) {
202+
throw new SLException(e);
203+
}
204204
}
205205

206206
private String[] getArchivePartIds(ProcessContext context) {

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/stream/LazyArchiveInputStream.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ public synchronized int read(byte[] b, int off, int len) throws IOException {
8282
return bytesRead;
8383
}
8484

85-
public InputStream getCurrentInputStream() {
86-
return currentInputStream;
87-
}
88-
8985
@Override
9086
public synchronized int available() throws IOException {
9187
// The return value of this method must be anything except 0

0 commit comments

Comments
 (0)