Remove unnecessary wrapping of IOException in DiskCacheToken.
Instead, catch the exception at the artifact level and log it
with some context.

Change-Id: Idf40e5c09dc2b9a91c8ae96d8ba79f6f69890410
Review-Link: https://gwt-review.googlesource.com/#/c/2020/

Review by: mdempsky@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11537 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java b/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
index 067c238..394f6a5 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
@@ -226,7 +226,7 @@
       Util.copyNoClose(in, out);
       Utility.close(in);
     } catch (IOException e) {
-      logger.log(TreeLogger.ERROR, "Unable to read or write stream", e);
+      logger.log(TreeLogger.ERROR, "Unable to copy artifact: " + getPartialPath(), e);
       throw new UnableToCompleteException();
     }
   }
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java b/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
index 8fbb6f8..e8c1154 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
@@ -63,7 +63,12 @@
   @Override
   public void writeTo(TreeLogger logger, OutputStream out)
       throws UnableToCompleteException {
-    diskCache.transferToStream(token, out);
+    try {
+      diskCache.transferToStream(token, out);
+    } catch (IOException e) {
+      logger.log(TreeLogger.ERROR, "Unable to copy artifact: " + getPartialPath(), e);
+      throw new UnableToCompleteException();
+    }
   }
 
   private void readObject(ObjectInputStream stream) throws IOException,
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
index c0b62d8..95858a5 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
@@ -50,7 +50,6 @@
     return new ByteArrayInputStream(diskCache.readByteArray(token));
   }
 
-  @Override
   public long getLastModified() {
     return lastModified;
   }
@@ -58,7 +57,12 @@
   @Override
   public void writeTo(TreeLogger logger, OutputStream out)
       throws UnableToCompleteException {
-    diskCache.transferToStream(token, out);
+    try {
+      diskCache.transferToStream(token, out);
+    } catch (IOException e) {
+      logger.log(TreeLogger.ERROR, "Unable to copy artifact: " + getPartialPath(), e);
+      throw new UnableToCompleteException();
+    }
   }
 
   private void readObject(ObjectInputStream stream) throws IOException,
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
index 0f33b66..6625870 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
@@ -510,7 +510,8 @@
         artifactStream.close();
       } catch (IOException e) {
         artifactLogger.log(TreeLogger.ERROR,
-            "Fatal error emitting this artifact", e);
+            "Fatal error emitting artifact: " + artifact.getPartialPath(), e);
+        throw new UnableToCompleteException();
       }
     }
   }
diff --git a/dev/core/src/com/google/gwt/dev/util/DiskCache.java b/dev/core/src/com/google/gwt/dev/util/DiskCache.java
index f966f1f..5f34d13 100644
--- a/dev/core/src/com/google/gwt/dev/util/DiskCache.java
+++ b/dev/core/src/com/google/gwt/dev/util/DiskCache.java
@@ -144,7 +144,7 @@
    * 
    * @return a token to retrieve the data later
    */
-  public synchronized long transferFromStream(InputStream in) {
+  public synchronized long transferFromStream(InputStream in) throws IOException {
     assert in != null;
     byte[] buf = Util.takeThreadLocalBuf();
     try {
@@ -167,8 +167,6 @@
       // Don't eagerly seek the end, the next operation might be a read.
       atEnd = false;
       return position;
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to read from byte cache", e);
     } finally {
       Util.releaseThreadLocalBuf(buf);
     }
@@ -180,7 +178,7 @@
    * @param token a previously returned token
    * @param out the stream to write into
    */
-  public synchronized void transferToStream(long token, OutputStream out) {
+  public synchronized void transferToStream(long token, OutputStream out) throws IOException {
     byte[] buf = Util.takeThreadLocalBuf();
     try {
       atEnd = false;
@@ -197,8 +195,6 @@
         length -= read;
         out.write(buf, 0, read);
       }
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to read from byte cache", e);
     } finally {
       Util.releaseThreadLocalBuf(buf);
     }
diff --git a/dev/core/src/com/google/gwt/dev/util/DiskCacheToken.java b/dev/core/src/com/google/gwt/dev/util/DiskCacheToken.java
index 36952ce..373558f 100644
--- a/dev/core/src/com/google/gwt/dev/util/DiskCacheToken.java
+++ b/dev/core/src/com/google/gwt/dev/util/DiskCacheToken.java
@@ -15,9 +15,9 @@
  */
 package com.google.gwt.dev.util;
 
+import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.OutputStream;
 import java.io.Serializable;
 
 /**
@@ -64,30 +64,12 @@
     return diskCache.readObject(token, type);
   }
 
-  /**
-   * Read the underlying bytes as a String.
-   * 
-   * @return the String that was written
-   */
-  public String readString() {
-    return diskCache.readString(token);
-  }
-
-  /**
-   * Writes the underlying bytes into the specified output stream.
-   * 
-   * @param out the stream to write into
-   */
-  public synchronized void transferToStream(OutputStream out) {
-    diskCache.transferToStream(token, out);
-  }
-
-  private void readObject(ObjectInputStream inputStream) {
+  private void readObject(ObjectInputStream inputStream) throws IOException {
     diskCache = DiskCache.INSTANCE;
     token = diskCache.transferFromStream(inputStream);
   }
 
-  private void writeObject(ObjectOutputStream outputStream) {
+  private void writeObject(ObjectOutputStream outputStream) throws IOException {
     diskCache.transferToStream(token, outputStream);
   }
 }