@Test public void testBucketOutputStream() throws IOException { this.expectedEx.expect(IllegalStateException.class); this.expectedEx.expectMessage( "Cannot open an output stream to a bucket: 'oss: ((WritableResource) this.bucketResource).getOutputStream(); }
@Override public OutputStream getOutputStream() throws IOException { if (isBucket()) { throw new IllegalStateException( "Cannot open an output stream to a bucket: '" + getURI() + "'"); } else { OSSObject ossObject; try { ossObject = this.getOSSObject(); } catch (OSSException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { ossObject = null; } else { throw ex; } } if (ossObject == null) { if (!this.autoCreateFiles) { throw new FileNotFoundException( "The object was not found: " + getURI()); } } PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); ossTaskExecutor.submit(() -> { try { OssStorageResource.this.oss.putObject(bucketName, objectKey, in); } catch (Exception ex) { logger.error("Failed to put object", ex); } }); return out; } }
OssStorageResource implements WritableResource { @Override public OutputStream getOutputStream() throws IOException { if (isBucket()) { throw new IllegalStateException( "Cannot open an output stream to a bucket: '" + getURI() + "'"); } else { OSSObject ossObject; try { ossObject = this.getOSSObject(); } catch (OSSException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { ossObject = null; } else { throw ex; } } if (ossObject == null) { if (!this.autoCreateFiles) { throw new FileNotFoundException( "The object was not found: " + getURI()); } } PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); ossTaskExecutor.submit(() -> { try { OssStorageResource.this.oss.putObject(bucketName, objectKey, in); } catch (Exception ex) { logger.error("Failed to put object", ex); } }); return out; } } }
OssStorageResource implements WritableResource { @Override public OutputStream getOutputStream() throws IOException { if (isBucket()) { throw new IllegalStateException( "Cannot open an output stream to a bucket: '" + getURI() + "'"); } else { OSSObject ossObject; try { ossObject = this.getOSSObject(); } catch (OSSException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { ossObject = null; } else { throw ex; } } if (ossObject == null) { if (!this.autoCreateFiles) { throw new FileNotFoundException( "The object was not found: " + getURI()); } } PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); ossTaskExecutor.submit(() -> { try { OssStorageResource.this.oss.putObject(bucketName, objectKey, in); } catch (Exception ex) { logger.error("Failed to put object", ex); } }); return out; } } OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory);  OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles); }
OssStorageResource implements WritableResource { @Override public OutputStream getOutputStream() throws IOException { if (isBucket()) { throw new IllegalStateException( "Cannot open an output stream to a bucket: '" + getURI() + "'"); } else { OSSObject ossObject; try { ossObject = this.getOSSObject(); } catch (OSSException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { ossObject = null; } else { throw ex; } } if (ossObject == null) { if (!this.autoCreateFiles) { throw new FileNotFoundException( "The object was not found: " + getURI()); } } PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); ossTaskExecutor.submit(() -> { try { OssStorageResource.this.oss.putObject(bucketName, objectKey, in); } catch (Exception ex) { logger.error("Failed to put object", ex); } }); return out; } } OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory);  OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles); boolean isAutoCreateFiles(); @Override boolean exists(); @Override URL getURL(); @Override URI getURI(); @Override File getFile(); @Override long contentLength(); @Override long lastModified(); @Override Resource createRelative(String relativePath); @Override String getFilename(); @Override String getDescription(); @Override InputStream getInputStream(); Bucket getBucket(); boolean bucketExists(); OSSObject getOSSObject(); boolean isBucket(); Bucket createBucket(); @Override boolean isWritable(); @Override OutputStream getOutputStream(); }
OssStorageResource implements WritableResource { @Override public OutputStream getOutputStream() throws IOException { if (isBucket()) { throw new IllegalStateException( "Cannot open an output stream to a bucket: '" + getURI() + "'"); } else { OSSObject ossObject; try { ossObject = this.getOSSObject(); } catch (OSSException ex) { if (ex.getMessage() != null && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { ossObject = null; } else { throw ex; } } if (ossObject == null) { if (!this.autoCreateFiles) { throw new FileNotFoundException( "The object was not found: " + getURI()); } } PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); ossTaskExecutor.submit(() -> { try { OssStorageResource.this.oss.putObject(bucketName, objectKey, in); } catch (Exception ex) { logger.error("Failed to put object", ex); } }); return out; } } OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory);  OssStorageResource(OSS oss, String location,
                              ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles); boolean isAutoCreateFiles(); @Override boolean exists(); @Override URL getURL(); @Override URI getURI(); @Override File getFile(); @Override long contentLength(); @Override long lastModified(); @Override Resource createRelative(String relativePath); @Override String getFilename(); @Override String getDescription(); @Override InputStream getInputStream(); Bucket getBucket(); boolean bucketExists(); OSSObject getOSSObject(); boolean isBucket(); Bucket createBucket(); @Override boolean isWritable(); @Override OutputStream getOutputStream();  }